My player only falls through the ground at HIGH VELOCITY. It seems playcanvas is calculating collision after movement in the physics or something like that. The ground has a collision and static rigidbody, the character has a dynamic rigidbody and collision on it.
Is there a way to force updating the collision before movement? What can we do to overcome this limitation?
Physics libraries tend not to handle these cases by default as it requires extra computation.
If you are dealing with high speed objects, you will want to use CCD as shown here https://developer.playcanvas.com/en/tutorials/physics-with-ccd/
You may also in general want to cap the falling velocity on the player as if it’s going that fast, it’s probably not a great experience for the user.
@yaustar Thanks for the quick response, we will work on implementing the CCD.
We got the CCD to work, is this documented anywhere? We did not know CCD was something we could use, the .body is not listed in the documentation.
It’s private API and uses the Ammo API (which is the open source physics library that we are using) directly.
Thank you for the assistance, it is appreciated.
The issue you are having is called a tunneling effect and is common in general purpose physics engines, like Ammo. You can google the term to learn more about it. Your goal is to make the distance between 2 simulation steps smaller, so that the player collider would hit the obstacle in one of these steps, rather than passing through.
CCD helps by adding additional calculation steps between the steps when solving the collision for CCD object. Keep in mind that Ammo CCD increases the CPU load. If you can get away without it - you should prefer that.
How to make sure the body collides? For example, as @yaustar mentioned, you can limit the maximum linear velocity of a rigidbody. The slower the object moves, the less distance it travels between two adjacent simulation steps. Another option is to make a ground thicker, like make it out of a thick cube or some other convex shape. A simple plane is much easier to skip than some volume. This will depend on the ground shape you have though, so might not be always feasible. Limiting the max velocity is your best option, probably.