How to rotate the forward vector to match the slope

Hi,
I want to rotate the forward vector to match the slope.
The code below is my attempt to solve it but with no luck,

I also tried this but didn’t work,

Can anyone guide me to solve it?

Im making the character move when attacking, activating flying mode when it happens,
Its going great on zero slope,
but on down slope it goes off ground,
and on up slope it doesn’t move and collide with the slope,

I wish to fix that and make it automatically going to the forward direction taking into account slope degree.

Get formal vector to the slope surface. Project it on X-Y (ie. zero Z value).
Now you have horizontal vector that shows down the slope direction.

You also have normal vector.

You need to project that down the slope vector on plane:

Then normalize it (just to be sure)

And use line trace to draw your debug vectors.

1 Like

Thanks @Nawrot,
Your answer solved it.

Project Vector on to Plane, I didn’t know this node, it’s a life savior.

Thanks a lot.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.