- Home /
rigid bodies passing through one another.
I have 2 x objects, a player and an enemy, which do not behave as they should when their rigidbodies collide.
Both are basic boxes with a rigidbody and a box collider. Both are moved using rigidbody.MovePosition in the FixedUpdate() function.
The player is controlled with WASD and mouselook. He collides with walls and collectibles etc no problem.
The enemy follows the player when the player is in range. If the player stands still at this point, the enemy moves closer until they touch and collisions are worked out perfectly.
If the player is moving and walks into the enemy, there is some initial resistance, then the player passes through the enemy.
I have searched the forums, but most other questions are regarding high velocities, or objects moving so quickly that they cross the collider of the other object before the collision registers. My objects are moving slowly, so it definitely isn't that problem.
Can anyone shed any light?
I can post any code which may help.
Thanks
Answer by meat5000 · Oct 08, 2013 at 11:17 AM
Move them using AddForce for complete physics. MovePosition simply registers a collision if it detects a collider between two points. The OnCollisionEnter routine will be called but the automatic rigidbody physics may not occur.
$$anonymous$$ovePosition was interfering with the collisions. Getting AddForce to actually move an object is proving problematic in itself, but that's a separate issue.
Thanks for the help.