How do I prevent my physics constraint from drifting?

I’m doing something like a noisemaker you hold in an FPS. Reference:


I create the stick handle part you hold.

I created the rattling head as a separate game object.

I attach a Physics constraint to the handle and position it where I want it. Then I set the two actors: handle as actor 1, rattler as actor 2.

Linear limits are all locked

Angular limits are locked except for twist (so that the rattler rotates on a single axis)

Linear motor is off

Angular motor is off

Projection is off

I turn Physics on on the rattler, and collisions to only hit static environments. I rather collisions be off, but if I do that, the rattler doesn’t attach to the handle at all.

Problem: when I translate in the game left, right, forward or backward, you can see the rattler drifting a little bit positionally (as if on a small spring). Other than that it works as expected.

Questions: How do I remove the drift? The rattler should be solidly on the handle only rotating on one axis as you move around.

Side question: Is there a way to have collision off on the rattler and have the physics constraint still work?

My educated guess: The FPS player is updated during the physics update, then the gun is put on the hand post physics update. Since the physics constraint does its thing during the physics update, and places the rattler on the handle during it, the rattler ends up a frame behind.

Possible Fix: Don’t use a physics constraint. Place the rattler on the handle myself in a tick post physics. Apply forces proportional to the world location and rotation delta of the rattler from frame to frame. Attaching one actor to another (using AttachTo) turns off physics on the second actor automatically, so I have to attach it myself in code during the tick. Can anyone think of a better way?

Have you tried turning projection on, with a low tolerance?
That should keep the head from moving away from the handle.
I had had a similar issue ( one of the contrained actors moving where it should not ) and projection helped.

You should try to use only swing1 or swing 2, so just one of them. I guess its just swing1 you need so it allows turning on the xy plane which should be Yaw. Hope that helps.
Cheers.