rigidBody.MovePosition() skips collisions

Hi all.

I have following situation (iOS and android oriented game): object with attached rigidboby, when object is pressed, it moves with the finger on Update().

Update()
{

if (isDragging)
mainRigidbody.movePosition(pos);

}

Than I have another object I need to collide with, but during fast movement of object 1 collision (I use onTrigger function) is not called.

Can anybody advice me how to fix that situation?

Here was my solution to this problem.

Cast a ray from your current position to the desired movePosition. Check if we hit a collider. If so move to the hit location, if not then move as usual.

Vector3 direction = new Vector3(desiredPosition - currentPosition);
Ray ray = new Ray(currentPosition, direction);
RaycastHit hit;
if (!Physics.Raycast(ray,out hit,direction.magnitude))
     rigidbody.MovePosition(desiredPosition);
else
    rigidbody.MovePosition(hit.point);

I know this from a while ago, but did you end up figuring it out? @anton_sl

There is no solution in the sense that there will always be the chance of an extremely fast object literally missing the collider wall altogether. The only way to stop this would be to have a restriction on the maximal speed, or have an infinitely-wide collider.

But, maybe this will help:

(1) make sure you test for collisions
in FixedUpdate(), not Update(), so
that the checks occur at exact regular
intervals, without the risk of
framerate reduction when the CPU is
working extra hard (e.g. when
scrolling fast!).

(2) to address the collision-miss,
that still could occur with if you
follow (1), make sure you

(2.1) have a wide-enough collider. You
could even program the game so that
the collider scales-out when an object
is moving very fast. A thin collider
has a higher risk of never being
touched during the FixedUpdate calls.

(2.2) Failing that, you could record a
boolean for the object saying
“isLeftOfWall”, which switches to true
after the object goes through the
wall, even if no collision is
detected. This can be implemented by
checking the coordinates of the wall
with the current transform.position to
see if your object is left or right of
the wall. (Obviously you can do this
trick for any axis, not just
left/right). Then you just call the
collision function (or another
function that does the same stuff) as
if there was a collision detected.

I would recommend using (2.1). There is no reason why your wall couldn’t have a HUGE collider, or two trigger colliders on the left and right side of it, that just reports whether the object is inside it or not.

Maybe you can try to put rigidBody.MovePosition() in FixedUpdate(). In this way the changing in position is synchronized with the physic, namely with collisions

Apparently rigidbody’s “continus” mode helps, (I’m trying to figure it out), but if not, raycast works always.

Have you tried changing the RigidBody’s Collision Detection to “Continuous Speculative”? – They just added it to specifically solve this problem.

I run into the same problem and it was horrible.
Only way that worked for me is to use rigidbody.velocity again and it works like a charm just don’t use MovePosition & the like it’s horrible.