Keeping the player upright whilst facing a wall using body gyro

I’m trying to figure out how to keep a player upright whilst facing a wall. I have a ray casted out to detect if there’s a part in front of the player, then the humanoid’s platform stand is set to true, then body gyro is inserted and from there sometimes there’s a tilt in the player(look in the image below). I’m trying to figure out how to remove the tilt and just keep the player upright. It’s a really big issue and the player NEEDS to be upright or else the player will slowly move backwards or in whichever direction.

Thanks to anyone who can help me out!

Code:

`local ray = Ray.new(Base.CFrame.p,Base.CFrame.lookVector*.8)
local hit,pos = workspace:FindPartOnRay(ray,character)

		if hit then
			humanoid.PlatformStand = true
			local bodyGyro = Instance.new("BodyGyro")
			bodyGyro.CFrame = Base.CFrame
			
			local bodyVelo = Instance.new("BodyVelocity")				
			bodyVelo.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			
			wallClimbVariables.bodygyro = bodyGyro
			wallClimbVariables.bodyvelo = bodyVelo
			bodyVelo.Parent = Base
			bodyGyro.Parent = Base
			
		end`

Images:


https://gyazo.com/d128742bd8b18af7f8215529855902b4
(note that the player rotating to the side is NOT a bug, it’s just the player moves away from the wall and is facing away from it whilst walking up to it.)

you could force the cframe of the humanoidRootPart to look into the direction the wall is facing along side the bodygyro (forcing one vector to stay the same). depending on what normal it hits it’ll make the humanoid face the opposite normal by making it negative

How would I go about doing that?

cframe has an lookat option i think. which is CFrame.new(position, lookat) however this requires you to possibly redo the script a little and not use a body gyro. the other option can be to lock one of the axis on the player’s positon so it can’t go to that direction (also done by cframing it) e.g.

CFrame.new(LockedXPos, PositionY, PositionZ) 
// rotation remains the same and affected by the body gyro

which might be a more simple sollution

Do you have a discord? I’d like to talk to you about it there

Try rotating the player’s Z orientation (in object space) to align with the wall as soon as the player starts climbing

This has already been inplented a while ago. The possibility we found a sollution for this last night (UTC +2) is big but not certain yet.

What about setting the cframe to be upright on a loop?

adjusting the CFrame whist theres a bodygyro in the object isn’t smart. they’ll contradict eachother and it won’t move at all.