- Home /
Collisions don't work properly
I have such scene:
I move platform with this code:
float xMovement = xAxis * Time.deltaTime * 20;
float yMovement = 0;
float zMovement = yAxis * Time.deltaTime * 20;
transform.Translate(xMovement, yMovement, zMovement);
When I move it not so fast, it works properly, but when it moves faster - the box falls through the walls and falls down. The properties of box and walls are these:
Answer by syclamoth · Nov 13, 2011 at 01:33 PM
Transform.Translate doesn't really care about collisions. If you are lucky, and the translation is small enough that it doesn't go all the way through your collider, the rigidbody will push the object back out in the next FixedUpdate, but otherwise collisions won't be detected at all.
You should be using
rigidbody.MovePosition(transform.position + movement);
or, better still, use rigidbody.AddForce() to simulate actual physical movement. For platforms rigidbody.MovePosition should work- but make sure that you do it in the FixedUpdate step.
Are we dealing with a very fast-moving platform here? Try setting the collision detection mode to 'Continuous Dynamic'- and the same with anything resting on it.
Speed is about 10 coordinat units per second. Continuous Dynamic didn't help.
Well, looks like it's time to get into unusual physics engines. Do you speed up gradually, or does it immediately travel at that velocity?
In any case, you need to have some way of deter$$anonymous$$ing what rigidbodies are inside the box (probably through OnTriggerStay or something). You then have to manually either set the velocities of those rigidbodies, or make them transform children of the box.