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
Jitters when reparenting a rigidbody #2512
Comments
|
@Maclay74 |
Hey, sure, is there a way I could share it only with the team? Can't publish it and we don't have a repository yet. |
|
Ahh... yeah...you could do that via the Unity editor by submitting a bug and sending me the email response you get with the bug submission ticket number (I can then get QA to forward that to our bug DB and access the project that way). Another thing I noticed is that you might be referencing older/legacy code (or the documentation is). |
|
Alright, I don't want to bother more people with that, to be honest. I see that in the updated example there is additional line pickUpObjectRigidbody.interpolation = RigidbodyInterpolation.None;that might be the key. I'll give it a test and have a closer look at the code. |
|
I gave it a try, unfortunately, it didn't help. So, there is small repro I have, the code I shared is from There is a issue with client transform as well, but please just ignore it. Controls - WASD, E is for the action. Thanks! |
|
Will look over this and report back to you any findings and/or an update version that resolves the issue. |
|
@Maclay74 I just modified the ClientNetworkTransform to disable the CharacterController for non-owner instances: I then culled down the complexity of the parenting action to just setting the server side to kinematic, setting the position to the same world space position as the pickup socket, left the local space settings alone for the NetworkTransform, and used the NetworkObject.TrySetParent: For the drop action, I just used the NetworkObject.TryRemoveParent, and set the server-side to not kinematic. The one issue you might run into is the mixing of owner authoritative NetworkTransform (the player) and server authoritative NetworkTransform (the cubes) as they will be relatively out of sync and can cause a delay in the update (especially on a client where the server has to be updated of the client player's position which, in turn, will update the cube's position that the server then has to update the player's cube instance). You might think about changing the cube to use a ClientNetworkTransform (without the above modifications) and change the ownership of the cube when it is picked up, but there is a bit of a trick to this as you have to make a custom (derived) NetworkRigidBody to handle the changing of the owner's kinematic setting after it has defaulted it to non-kinematic when ownership is changed. Oh, and I disabled the SceneManager and just assigned the NetworkManager's player prefab property with the Player prefab (still haven't verified if this made a difference or not...sort of got carried away a bit trying to narrow down the issue...so if I find some additional time I will re-apply the above changes without make any other modifications to double verify that just disabling the non-owner's CharacterController was all that was really needed). |
|
Here is a video of the applied updates: Here is the Code folder with the applied updates: Let me know if this resolves your immediate issue, and if you need any assistance with making the cube work with an owner authoritative NetworkTransform and customized NetworkRigidBody. 👍 |
|
I... can't find suitable words to express how I appreciate such a detailed research! I tried your changes, and indeed the cubes don't move to the origin on drop, although there is a jitters when character rotates with a cube "in hands". It feels like the cube goes in the opposite direction at the beginning and swings back then. It's very hard to capture because it happens very fast, I'm not sure you have the same problem on the video you posted, but here is mine carrying_jitters.mp4About the issue you mentioned with mixing transforms - I think I could use client authoritative cubes with changing ownership, but I don't understand one thing. I have a problem with the host (server authority) carrying a cube (server authority) and then results of it are streamed to a client. So client's player (client authority) isn't the part of the "equation", is it? With that in mind I changed protected override bool OnIsServerAuthoritative() => true;and the jitters persist. I probably miss something still, it's little hard to wrap my head around these dependencies. |
|
Ok. |
|
I always move the host, never the client (in fact, client can't carry cubes for some reason, but it's a problem of tomorrow's me) Anyway, you disabled |
|
Ok, I had to make a number of changes that might seem a bit confusing but for picking up objects with an owner authoritative player NetworkTransform and a server authoritative object NetworkTransform this approach will yield the best results as you can see below: ClientNT-PickupServerNT.mp4Server Authoritative NetworkTransform Objects
The One neat trick that isn't discussed a bunch is that once a NetworkObject is spawned it keeps references to all of its associated NetworkBehaviour components...even on nested children...which there is no rule saying you can parent a GameObject with NetworkBehaviour components under another GameObject that does or does not have NetworkObject component! 😸 The Where once again, we leverage from the Action SystemOne thing you should consider is possibly simplifying your action system (i.e. remove it/set it to the side at this stage) while you are working on the core mechanics as there are some problematic areas in there that could give you false positives that could slow down your core mechanics progress. Detecting What To PickupTo detect whether a player can pick something up or not, I would exclude using collision boxes as triggers to populate objects as there are other elements to the changes made which could impact that approach (i.e. having the CharacterController exclude anything in the "Ignore" layer and include anything in the "Default" layer to help with the transition when picking things up) And you could have an "inventory" for the player where once it is picked up it could simply just add that to a list of Objects the player is holding (or just one while prototyping). Not trying to downplay your approach or anything like that, they were just some observations made while looking for the right solution to meet your project's needs. Either case, here is the project with the above modifications... I changed some of the packages to better suite my current setup here so sorry about that... you might have to extract what you want to keep into your version (once you get a repo setup it will make this kind of update a bit simpler). This should get you past the issue you were having with picking up an object and the associated jitter you were experiencing (with a small bonus of the player sort of "tossing" the cube forward when it is dropped 😸 ) Cheers, -Noel |
|
Oh yeah... on the non-authoritative instances it is possible to pick something up when the non-authority side is still a bit further away from the target object. There are several ways to handle this synchronization... one of the simpler approaches would be to add one more "intermediate" GameObject between CubeObject and Cube that you could adjust when parented based on the distance from the socket and the Cube itself. The general idea here is that you can always adjust normal GameObject's transforms that are not tied to a NetworkTransform to work around some of these latency related issues. Sometimes a little "smoke and mirrors" are more effective than trying to gain the precise synchronization...
Anyway, let me know if this resolves your issues and meets your project's needs? |
|
Wow... This is just insane, such level of support must be illegal! You should write a book, it would be a bestseller! You even added music to the video! I need some time to process all this information, but what I see is that it definitely solves my problem! |
|
@Maclay74 Cheers and Happy Netcoding! 😸 p.s. We always enjoy seeing projects progress... so feel free to post any advances in your project (you feel comfortable sharing) through video or screenshots. It is always fulfilling to see projects evolve. 👍 |
|
Will take a gander at it and see where my disconnected thoughts were at the time. 😹 |
|
Ok, |
|
Gotcha! Look forward to checking it out! |
|
@Maclay74 The end result: I just zipped up the Assets folder since I sort of made some more editor related updates while I was working on it. This should give you a good start and is actually a better approach than the first one. Don't enable half float precision until you see release/v1.4.0 get merged into the develop branch as there was a fix in that branch for properly resetting the position interpolator when a non-authoritative side gets a teleport state (otherwise you will see weird anomalies). Once you see that merged and/or v1.4.0 is public (in the package manager) then you can enabled half float precision on the cubes. Also, I am going to pass along this approach to the MTT samples team so they can come up with some better name for the "CustomNetworkRigidBody" component... it will just be that and the ClientNetworkTransformCube that I think other users might find useful to handle a client authoritative way to pick up "things" that have rigid bodies (using v1.4.0 that is). Cheers, -Noel |
|
@NoelStephensUnity thanks again! I managed to implement your changes to my initial project and everything now is butter smooth! I'm sure that the example would be appreciated by the community, since the one that I've followed doesn't provide accurate result. So, the issue is 110% resolved! I am so inspired now! |
|
Excellent! 🚀 Happy Netcoding! |




Description
Following this part of the documentation I'm trying to implement the carrying behavior. It works, but with noticeable jitter when character drops the object.
This is my pick up code (it actually matches the documentation example):
And drop:
Reproduce Steps
Actual Outcome
Object teleports for a moment to 0,0,0 (apparently, not sure) and then teleports back to its correct position.
Also, it also participates in physics simulation, so it can move other objects located in 0,0,0 (you can see on the video that it pushes another character)
Expected Outcome
Object should persist it's current position without teleports or jitters
Screenshots
Host is on the left. Jitters appear only on the client.
jitters_edit_0.mp4
Environment
developbranch, the same results.The text was updated successfully, but these errors were encountered: