Consider a simple 2D platformer. I have a BoxCollider2D on the player object and a TilemapCollider on the ground below(grid). I created a "jump" script for the player through which the player object jumps and comes back to the ground, clean. But when the player object goes relatively high and comes down with a high velocity, it doesn't collide with the ground(grid) instead it goes right through the tilemap collider and into the void.

How can this behaviour be prevented?


To prevent a collider from passing through another collider at high velocity, change the "Collision Detection" option on its "Rigidbody 2D" from "Discrete" (default) to "Continuous".

Inspector of Rigidbody 2D

Note : Continuous collision detection has overhead and will have impact on the engine performance, but will provide a much better collision detection system.

  • 2
    \$\begingroup\$ FYI, CCD casts a ray between the last and current position, checking against all objects whose bounding boxes intersect the bounding box of that ray. This is why it will never miss anything it should collide with. Having said that, it is more expensive than the purely iterative approach taken by discrete CD, since the latter checks only the current position, rather than along a ray. \$\endgroup\$ – Engineer Dec 1 '20 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.