1
\$\begingroup\$

I have implemented a collision and response system based on the famous "Improved Collision detection and Response" paper. However I'm having an issue with objects sliding backwards on slopes. I believe I could circumvent this issue if I understood how to find the angle of the plane of which my object is colliding with. Take the below screenshot as an example of the situation:

enter image description here

I know the following data:

  • Position of player object (the ellipsoid at the bottom of the ramp)

  • Vertices of the collision triangle

  • Normal of the collision triangle
  • Intersection point between player object and collision triangle
  • Penetration distance between player object and collision triangle

How can I use this information to determine the angle of the collision triangle?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

If you have the normal of the collision triangle, then you can do a dot product with a normal pointing up (0, 1, 0), the result will be related to the angle of the surface (0 when is completety vertical, 1 when it's completely flat, and in between)

That should be really all, you check that against a threshold to determine if you want the ellipsoid to slide or not.

I actually followed that same paper and this is how I implemented (my Up vector was 0,0,1)

// Check if the slide is too steep for gravity 
if (is_gravity) {
    var v1 = vector_normalize(velocity),
        v2 = [0, 0, 1 * sign(v1[2])],
        dp = dot(v1, v2);

    if (dp <= 0.70) {
        return true;
    } 
}
\$\endgroup\$

You must log in to answer this question.

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