0
\$\begingroup\$

Can anyone help me to better understand the concepts behind this algorithm?

I've seen this phrase come up several times during my research into creating a 3D character controller, but am having issues finding much information about it. One example is from a user manual that accompanies a character controller asset on the Unity asset store.

I'm used to handling collisions in 2D that involve primitive colliders, so most of the time I simply move my entity, check for overlaps, and then calculate the shortest distance out of the primitive (if one is using Unity, he or she can also use the ColliderDistance2D API for this). It seems like "collide and slide" might be a bit more involved, especially in 3D where contact with a mesh may be the norm instead of contact with primitives. From the manual I linked earlier it seems that an entity's movement vector is altered based on the normal of the surface with which that entity collides, but where does the actual collision (overlap) occur, and how do we resolve it?

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

When we are talking about Collide and Slide, it means that whenever our controlled collider contacts with another collider (for example a wall), instead of stopping our movement, we can use the angle between our wall-normal and hit vector, to slide along the wall, which can be achieved by vector projection.

Unity has a nice method called Vector3.ProjectOnPlane for this job. Of course there are many other ways to achieve this effect or customize it base on your needs.

The Unity character controller component handles this algorithm automatically, so if you use a character controller component for movement, whenever you hit on a wall with an angle you can see the sliding effect.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, this is pretty much the explanation I was looking for. But what happens if the collider finds itself inside or intersecting another collider? Obviously this won't happen through pure movement, since one will be checking for contact before moving, but a different collider - say, from an enemy or some moving platform - could cause this to happen. \$\endgroup\$ Mar 9, 2021 at 5:43
  • 1
    \$\begingroup\$ well, mostly this algorithm is used for static objects, but if you are using it for a moving object then you shouldn't have any difficulties because one way of preventing colliders from intersecting is using this algorithm! @GingerandLavender \$\endgroup\$ Mar 9, 2021 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .