Pawl
1
I’ve got a Rigidbody2D sprite that’s a child of a rotating circle (the circle does not have a RigidBody2D). When I click the mouse in Update(), I unparent the sprite using SetParent(null) and apply an outward force using AddForce(force, ForceMode2D.Impulse) to the sprite.
When I set the timescale low, I see the sprite jumps a short distance, then pauses for 5-10 frames, and then starts to move smoothly as expected. The short pause is not expected.
When I simply remove the SetParent(null) call, I do not see this short pause. Unfortunately I can’t use this as a practical solution as I do need to unparent the sprite.
I’ve tried calling Physics2D.SyncTransforms() after unparenting, changing the interpolation type for my Rigidbody2D and adjusting Time.fixedTimestep but nothing changes. I also tried waiting a few frames to apply the force after unparenting, but it seems I need to WaitForEndOfFrame() 15-20 frames for this to remove the jitter.
Does anyone know if it’s “invalid” to unparent an object the same frame as trying to apply physics?
Try to use FixedUpdate instead of Update. For more information: Unity Connect
Pawl
3
To answer my own question, this seem to simply be a limitation with how Rigidbody2D and transform parenting works.
To work around this, rather than change the parent of my Rigidbody2D object, I create a dummy GameObject and dynamically add it as a child of the rotating circle. Then in Update(), I simply set the position and rotation of my Rigidbody2D object to match the dummy object. This removes the jitter while still allowing me to use the Rigidbody2D for dynamic physics when needed.