-
Notifications
You must be signed in to change notification settings - Fork 458
fix: networktransform SwitchTransformSpaceWhenParented forces updates when InLocalSpace is true #3664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoelStephensUnity
wants to merge
54
commits into
develop-2.0.0
Choose a base branch
from
fix/networktransform-autoswitchspace-forcing-updates-localspace
base: develop-2.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: networktransform SwitchTransformSpaceWhenParented forces updates when InLocalSpace is true #3664
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
5a83370
fix
NoelStephensUnity 952a40b
fix
NoelStephensUnity 983bd1b
update
NoelStephensUnity 1d36492
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity 9adf1e5
update
NoelStephensUnity 6440658
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-lo…
NoelStephensUnity 46d1854
update
NoelStephensUnity 197f4b0
update
NoelStephensUnity 7ab9dc1
Doc pass on NetworkTransform additions
jabbacakes d3347bd
fix
NoelStephensUnity b26de65
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-lo…
NoelStephensUnity db33128
Update com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
NoelStephensUnity ba36860
Update com.unity.netcode.gameobjects/Runtime/Components/NetworkTransf…
NoelStephensUnity ddc7c36
Update com.unity.netcode.gameobjects/Runtime/Components/NetworkTransf…
NoelStephensUnity c489e6f
Update com.unity.netcode.gameobjects/Runtime/Components/NetworkTransf…
NoelStephensUnity ae61807
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity 2521520
refactor
NoelStephensUnity 649b989
style
NoelStephensUnity a267896
style - PVP
NoelStephensUnity 4605249
update
NoelStephensUnity 4917d40
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity 1dc4e4f
update
NoelStephensUnity 07731e5
update
NoelStephensUnity e444a1b
update
NoelStephensUnity 25bfb07
update
NoelStephensUnity 06f2ead
upate
NoelStephensUnity 41f8c36
style
NoelStephensUnity ef5090f
test
NoelStephensUnity 7d05df9
Apply suggestions from code review
NoelStephensUnity fb99ba2
doc: update
NoelStephensUnity 0908d74
doc: style
NoelStephensUnity aef1185
style - PVP
NoelStephensUnity 473fcd8
update
NoelStephensUnity 885452a
fix
NoelStephensUnity e24aff1
test and style
NoelStephensUnity b0e4510
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity 0a35b95
update
NoelStephensUnity bc20e16
update
NoelStephensUnity 5f34872
update
NoelStephensUnity cf27a00
update
NoelStephensUnity 8af2c0e
Docs pass on new content
jabbacakes 909be07
Reinstating note
jabbacakes a65d89e
Updating landing page
jabbacakes 4df63ea
refactor
NoelStephensUnity 99a33cf
Merge branch 'fix/networktransform-autoswitchspace-forcing-updates-lo…
NoelStephensUnity a4e8570
update
NoelStephensUnity 400172f
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspac…
NoelStephensUnity f8a8125
update
NoelStephensUnity 1f435e0
update
NoelStephensUnity 79b602a
fix
NoelStephensUnity dea7aae
fix
NoelStephensUnity d71ebca
fix
NoelStephensUnity 6f87b1d
refactor
NoelStephensUnity 44df5f4
style - PVP
NoelStephensUnity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
457 changes: 425 additions & 32 deletions
457
com.unity.netcode.gameobjects/Documentation~/advanced-topics/physics.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
com.unity.netcode.gameobjects/Documentation~/components/helper/networkrigidbody.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# NetworkRigidbody | ||
|
||
NetworkRigidbody is a component that sets the Rigidbody of the GameObject into kinematic mode on all non-authoritative instances. Authority is determined by the [NetworkTransform component](networktransform.md) (required) attached to the same GameObject as the NetworkRigidbody. Whether the NetworkTransform is server authoritative (default) or owner authoritative, the NetworkRigidBody authority model will mirror it. That way, the physics simulation runs on the authoritative instance, and the resulting positions synchronize on the non-authoritative instances, each with their RigidBody being kinematic, without any interference. | ||
|
||
## Configure NetworkRigidbody | ||
|
||
 | ||
|
||
When looking at a NetworkRigidbody in the Inspector view, there are three exposed values: | ||
|
||
- __Use Rigid Body for Motion__ | ||
- When enabled and using a [NetworkTransform](networktransform.md), the NetworkTransform uses the PhysX position and rotation to synchronize changes during the `FixedUpdate` loop update stage. | ||
- __Auto Update Kinematic State__ | ||
- When enabled, NetworkRigidbody automatically determines whether the current instance should be kinematic or non-kinematic. | ||
- For custom solutions, you can opt to disable this field or derive from [NetworkRigidbodyBase](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.5/api/Unity.Netcode.Components.NetworkRigidbodyBase.html) and design your own custom networked Rigidbody handler. | ||
- __Auto Set Kinematic On Despawn__ | ||
- When enabled, this option makes the rigid body kinematic when despawned (which can be useful for [object pools](../../advanced-topics/object-pooling.md)). | ||
|
||
Some collision events aren't fired when using NetworkRigidBody: | ||
|
||
- On the server, all collision and trigger events (such as `OnCollisionEnter`) fire as expected and you can access (and change) values of the `Rigidbody` (such as velocity). | ||
- On clients, Rigidbody is kinematic. Trigger events still fire but collision events won't fire when colliding with other networked Rigidbody instances if your project's physics settings is set to the default contact pairs. | ||
 | ||
|
||
- You can adjust the __Contact Pairs Mode__ to use kinematic and non-kinematic by setting it to __Enable All Contact Pairs__. | ||
|
||
> [!NOTE] | ||
> If there's a need for a gameplay event to happen on a collision, you can listen to the `OnCollisionEnter` function on the server and synchronize the event via `Rpc(SendTo.Everyone)` to all clients. If you plan on handling many collisions, then it's recommended to use the [RigidbodyContactEventManager component](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.Components.RigidbodyContactEventManager.html) to handle collision checking during a job (`OnCollisionenter` can become expensive from a processing perspective if you have enough instances colliding). | ||
|
||
### NetworkRigidbody2D | ||
|
||
NetworkRigidbody2D works in the same way as NetworkRigidbody but for 2D physics (Rigidbody2D) instead. | ||
|
||
## Rigidbody interpolation example | ||
|
||
While NetworkTransform offers [interpolation](../../learn/clientside-interpolation.md) as a way to smooth between delta state updates, it doesn't get applied to the authoritative instance. You can use `Rigidbody.interpolation` for your authoritative instance while maintaining a strict server-authoritative motion model. | ||
|
||
To have a client control their owned objects, you can use either [RPCs](../../advanced-topics/message-system/rpc.md) or [NetworkVariables](../../basics/networkvariable.md) on the client-side. However, this often results in the host-client's updates working as expected, but with slight jitter when a client sends updates. You might be scanning for key or device input during the `Update` to `LateUpdate` stages. Any input from the host player is applied after the `FixedUpdate` stage (such as physics simulation for the frame has already run), but input from client players is sent via a message and processed, with a half RTT delay, on the host side (or processed 1 network tick + half RTT if using NetworkVariables). Because of when messages are processed, client input updates run the risk of being processed during the `EarlyUpdate` stage which occurs just before the current frame's `FixedUpdate` stage. | ||
|
||
To avoid this kind of scenario, it's recommended that you apply any changes received via messages to a Rigidbody after the `FixedUpdate` has run for the current frame. If you [refer to how NetworkTransform handles its changes to transform state](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/a2c6f7da5be5af077427eef9c1598fa741585b82/com.unity.netcode.gameobjects/Components/NetworkTransform.cs#L3028), you can see that state updates are applied during the `Update` stage, but are received during the `EarlyUpdate` stage. Following this kind of pattern when synchronizing changes to a Rigidbody via messages will help you to avoid unexpected results in your Netcode for GameObjects project. | ||
|
||
The best way to address the issue of physics latency is to create a custom NetworkTransform with a custom physics-based interpolator. You can also use the [Network Simulator tool](https://docs.unity3d.com/Packages/com.unity.multiplayer.tools@latest?subfolder=/manual/network-simulator) to spot issues with latency. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an artifact from earlier changes... just reflecting what it is currently in the main v2 branch.