Rotating Vector to Slope

What im trying to do

I made a character controller and I’m trying to make slope movement smoother.
One way to do this is to rotate the move direction to the normal of the slope your standing on.
Iv done this in Unity before and its rather simple there. But on roblox i have no idea how to do this.

Unity Example

A good example for what im trying to do is this Unity tutorial that iv used many times.

Help me!!

Iv been trying to figure this out for months now… That may seem like a long time but im not that smart with these sort of things : P

1 Like

a² + b² = c²


I’m only joking. That isn’t even what Pythagorean theorem is used for lol.

I am unsure if there is actually a way to do this effectively, but if you will pardon the time it will take, then I am glad to help you out.

1 Like

If you are willing to help I would be very grateful! Also I’m not in a hurry.

1 Like

A Couple of Advanced CFrame Tricks - Resources / Community Tutorials - DevForum | Roblox

1 Like

Alright!

I’m very unsure though, so maybe try what @kylerzong did in post #4 in the meantime.

2 Likes

Should be able to pull it off like this. There are simpler ways, but this is the ‘correct’ way which guarantees there won’t be any ambiguity.

local base = starting_cframe
-- Change this next line to whatever position you want 'rotated_cframe' to be at.
-- If you just want it to be zero so that 'rotated_cframe' is rotation only, set it to
-- Vector3.zero
-- I started it at starting_cframe.Position so that you can specify starting_cframe
-- and just rotate it in place how you need it.
local rotated_pos = base.Position
local y_vector = slope_surface_normal
local x_vector = base.LookVector:Cross(y_vector).Unit
local z_vector = base.RightVector:Cross(y_vector).Unit
rotated_cframe = CFrame.fromMatrix(rotated_pos, x_vector, y_vector, z_vector)
6 Likes

WOAH! This seems to of worked! Took me a bit to figure out how I fit it into my code but it works! Thank you!

1 Like

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