Alligning character to the wall side ways using CFrame?

So I’m making a parkour game and before this issue, I’ve made the character successfully face the wall when it wants to scale the wall.

Anyway, that was for climbing, right now I’m making the second part allowing the player to wall-run which also works fine, the only thing I want to add is to make the character face the wall it’s running, but sideways. this works for walls that are rotated -45 degrees, but not on walls in other directions. I’m trying to make this dynamic and I’ve tried several things.

CFrame_Line:

--hrp being rootpart
CFrame.new(
	hrp.CFrame.p
	,Vector3.new(hrp.Orientation.X
	, wallpart.Orientation.Y - rightcastresult.Normal.Y
	, hrp.Orientation.Z
	)
)

I’ve tried adding 90 degrees to the CFrame like

CFrame_Line*CFrame.Angles(0,math.deg(90),0)
--or
CFrame_Line*CFrame.Angles(0,math.rad(90),0)
--tried this knowing full well radians wouldn't 
--work anyway since I lost hope in myself

I’ve tried using RightVector

CFrame.New(CFrame_Line.Position, CFrame_Line.RightVector)

but none proved any different.
right now I have footage of it working on 1 type of wall in a particular direction, and also not working on other wall directions:

(file to big so use url) Issue wallrun* - YouTube

Here’s how the raycast works and how I want it to work. I’ve already set up the raycast just fine.

help

1 Like

You might be able to use CFrame:LookAt() plus a 90 degree turn to determine where the player looks

The constructor is CFrame.lookAt(), and you’ll need to perform a raycast too. Here’s some pseudo-code for further assistance.

local Workspace = workspace

local Parameters = RaycastParams.new()
Parameters.FilterDescendantsInstances = {Character} --Make sure the character is blacklisted.
local Result = Workspace:Raycast(HumanoidRootPart.Position, HumanoidRootPart.CFrame.RightVector * 5, Parameters) --Perform raycast from character's root to 5 studs right of character's root (or left if necessary).
if Result then
	HumanoidRootPart.CFrame = CFrame.lookAt(HumanoidRootPart.Position, Result.Position) * CFrame.Angles(0, math.pi / 2, 0) --Look at specific wall position from current position and rotate the character 90 degrees around the Y-axis (may need to be -90 degrees).
end
3 Likes

thanks for the reply,
was able to fix it my self in the end
a more detailed approach I’ve explained in the next article.