- Home /
Rigidbody.MovePosition/MoveRotation Hits far away colliders
Hello!
I've been dealing with this issue:
When I move an object with Rigidbody.MovePosition or Rigidbody.MoveRotation very fast, it will trigger a collision with nearby objects that are actually never in contact with it.
The MovePosition function is being called from Fixed Update.
The Rigidbody is set to Collision: Continuous Dynamic, Interpolate: Interpolate and IsKinematic: true.
It uses a Mesh Collider but I have the same issue with other types of colliders.
I've tried changing all settings but nothing worked. I've also tried changing the Default Contact Offset value in Project Settings > Physics. Changing the Fixed Timestep in the Time settings didn't work either. Also I'm locked at 72 fps so the framerate isn't an issue.
I say again, this occurs when I move the object REALLY FAST, (I'm doing it in VR but this also happens by just moving the object through the arrows in the editor). It seems like either the collider becomes bigger when moving fast or that the collider and the mesh missalign for whatever reason.
This does not happen if I move the object by teleporting it with Rigidbody.position, but that makes the collider miss sometimes the actual target collider.
For anyone wondering, the code is this (I'm just teleporting it to the hands position):
myRigidbody.MovePosition(target.transform.position);
Thanks for all answers and for your time.
Alfonso
Answer by keroltarr · Mar 09 at 02:59 PM
based on your description I wonder that even with 72 fps it is calculating given the extreme velocity of the object that it will have collided with the other object before it renders the next frame. if you are already scaling your movement by time.deltatime you might need to clamp the position to limit how far it can go or clamp speed to limit how fast it can go.
Thanks for the answer! I'm moving the object in the FixedUpdate. I can't clamp the position because it would break the immersion of the game unfortunately. Still, this seems to be more like a Unity bug the more I look into it.
Answer by Edy · Mar 09 at 04:46 PM
Try increasing the physics update rate. Default rate is 50 Hz, I'd try with 100 Hz.
The physics update rate is configured at Project Settings > Time > Fixed timestep. Default is 0.02 (50 Hz). Set it to 0.01 for 100 Hz. This may have some impact in the performance.
Physics "predicts" the collisions based on the speed of the objects. The lower the physics update rate, the farther away the contacts will have to be checked for. Increasing the physics rate would reduce the distance at which physics needs to check.
Visual framerate is irrelevant. Physics will always run at the configured update rate regardless the render update rate.
Thanks for your answer! I already tried to increase the physics update rate, but it did not fix the issue. I even went as far a to make it update 1000s of times per frame.