Download

Get Angle of Floor

Hi there!
I want to implement my own logic when my character steps onto a slope.

I need the angle of the floor below my character, but I don’t know how to retrieve it.
74b6378fd499ae529461b2121abe7a459e5e0ce7.jpeg

Google for DOT product, it gives you cosine of angle between 2 vectors.

In your case calculate dot product of impact normal and [0,0,1] vector. Then arc cos of it.

Thank you very much it works.

I wasn’t sure about Dot Product, because Dot Product returns an orthogonal vector iirc. What’s an orthogonal vector from 0,0,1 and 0,0,1 (flat surface?)

CROSS returns orthogonal vector. DOT product returns cosine.

sorry to revive an old thread, but i need some help with this topic, tried searching on google but i didn’t figure it out, any help will be very useful.

you need to calculate the Dot Product between the Vector (0,0,1) and your Floor Normal.
Use arccos on this and you get the angle in degrees. (you can omit arccos tho)

thank you, it worked.

Perfect topic! Thank you for your answers so far. I’m trying to implement the same setup with slope angle, but I want to detect if the angle is increasing or decreasing over time? How to store previous angle and compare it with current angle, so I can switch stuff ( like animation, and movement speed, and ground friction ) depending of that if you are going uphill or downhill?

Thank you !

You can take the Z Axis value from your Actor’s Location and compare it with the Z Axis value last frame. If the difference is a +ve value you’re going up and if it’s -ve you’re going down.

Kinda like this

In your tick() function

LocationLastFrame = LocationThisFrame; // Both variables are FVectors defined in Header file
LocationThisFrame = GetActorLocation();

float Difference = LocationThisFrame.Z - LocationLastFrame.Z; // Difference variable contains the value you need

if (Difference > 0.1)
{
// You’re going up
}
else if (Difference < -0.1)
{
// You’re going down
}

I may be forgetting something here but this is the gist of it. Hope it helps :).