first time poster.

I'm curious as to how I can obtain a vector that defines the downward slope of a 3D plane. The goal is to apply this to a player as a force to achieve a sliding mechanic, like in Mario 64 (for steep floors and slide levels).

example showing a vector perpendicular to the normal

My attempts at this used variations of this equation, but it's not quite what I'm looking for.

b * ( -2*(V dot N)*N + V ) where v is the vector that you want to reflect, n is the normal of the plane, b is the amount of momentum preserved (0.0 - 1.0).

this gives a reflected vector

I also have means to calculate the plane normal and get the intersection point of the player

Any other ideas to solve this are also appreciated

  • \$\begingroup\$ Was thinking, wouldn't you cross the Normal vector of the plane with the gravity Vector in this case (0, 1, 0) to get a perpendicular vector on the plane to the direction you are looking for. Then cross that Vector with your normal vector to get your slide vector with respects to the plane and the gravity vector. Doing this from memory, apologies if not quite right. \$\endgroup\$ – ErnieDingo Jan 22 '19 at 21:54
  • \$\begingroup\$ I'm pretty new to this type of vector math involving the cross product so I'm not too sure why using the global 'up' position works instead of global 'down'. I'm sure there's good reason though \$\endgroup\$ – benneyHacker Jan 23 '19 at 21:38
  • \$\begingroup\$ as per DMGregory's elaborated result. My suggestion was inline with this.\ \$\endgroup\$ – ErnieDingo Jan 24 '19 at 3:19

Take a vector representing your global up direction, and cross it with your plane normal.

This gives you a horizontal vector pointing across your slope. By the properties of the cross product it has to be perpendicular to both the plane normal (putting it in the plane) and the up vector (putting it in the horizontal plane).

Vector3 acrossSlope = Vector3.Cross(globalUp, planeNormal);

Now we can cross this vector with your plane normal again to get a vector pointing down-slope:

Vector3 downSlope = Vector3.Cross(acrossSlope, planeNormal);

Again by construction, this has to be perpendicular to both the plane normal (putting it in the plane) and the "across" vector (meaning it points up/down the plane, depending on the order you put the two arguments.

You can normalize the result to get it back to unit length.

  • \$\begingroup\$ That works perfectly, and a very simple solution as well. Thanks for the great response \$\endgroup\$ – benneyHacker Jan 22 '19 at 4:12

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.