When a rigidbody’s movement is constrained/influenced by a joint, the rigidbody’s linear and angular velocity properties no longer seem to be correct. I discovered this while implementing a simple pickup/release mechanic for our VR game. When picking up an object, I add a joint to the object being picked up, and assign the connectedBody of the joint to the kinematic rigidbody that represents my hand position. When releasing the object, I destroy that joint. This seems simple enough, but testing reveals that the object immediately changes direction the moment I release it rather than maintaining the movement it had at the time of the release. A bit of debugging reveals that the velocity values reported by the rigidbody while under the influence of the joint do not match reality. If I keep track of the previous position/rotation at each FixedUpdate, and then forcibly set the rigidbody’s velocities to my calculated values when destroying the joint, then everything behaves as expected.
If the velocity of the object is wrong when it’s in the joint, then why would this work?
The way I’m understanding the situation at the moment is telling me that this already happens automatically, but when you destroy the joint the object behaves erratically because the values didn’t make sense at the moment before release. Am I imagining the effect wrong? Maybe a .gif or video would clarify.
Could it be that destroying the joint creates some buggy impulse on the object?
Hyblademin, I think I may not have explained what I was seeing well enough. Let me try again:
As soon as the joint is attached, the velocity values reported by the rigidbody.velocity and rigidbody.angularVelocity do not match the actual movement of the object. If I keep track of the previous position and rotation at each FixedUpdate and compute the true velocities myself, they are quite different from what the rigidbody is reporting. When I then destroy the joint, the object suddenly changes its motion to align with those incorrect velocity values.
I’ll try and get a recording of this later.
There’s the part I wasn’t understanding.
Are you able to reproduce this in a minimal project? Did you submit a bug report?
I haven’t tried yet, although it’s on my list of things to do when I’m not quite so busy (although let’s be honest, when does that ever actually happen…)