astrochili / defold-kinematic-walker

Kinematic character controller extension for Defold
MIT License
37 stars 4 forks source link

Significant improvement in the smoothness of collision detection using the new paradigm #10

Open astrochili opened 1 year ago

astrochili commented 1 year ago

Since it is now possible to use fixed_update() and the motion of the physical body is now separated from the visual model, it is possible to significantly improve the smoothness of collision detection.

Previously this was not possible and a lot was built on some hacks. Now it is necessary to completely revise the algorithm.

In fixed_update() it is necessary to make movement and collect ALL collision messages. How to do it? For each collision message, collect all planes and normals of obstacles accumulatively, and each time calculate a new position based on all obstacle planes. And in the update already expose the model to the desired position.

Example implementation is described here in the Kinematic Character Controller section.

astrochili commented 10 months ago

In order to use all the collision planes, we will have to compute the position of the capsule ourselves, given its size. Essentially, all we need from collision messages is the normal, the rest is all useless, since the ejection force only takes into account one obstacle - the one it ejects from.

Some examples how to calculate triangle - capsule collisions: