Climbing Mechanic Problems

So I have this climbing mechanic and like it’s very buggy because depending on where the player is facing it will like mess up the whole thing not sure how to fix it heres a video of it.

if input.KeyCode == Enum.KeyCode.R  and not Climbing then
		local climbRay = Ray.new(humrp.Position, humrp.CFrame.lookVector * 5)
		local hit, position, surface = game.Workspace:FindPartOnRayWithIgnoreList(climbRay, {humrp})
	if hit then
		print(surface)
		Climbing = true
		hum.PlatformStand = true
		print("Climbing Enabled.")
		local mag = (position - humrp.Position).Magnitude
		local attachment = Instance.new("Attachment")
		attachment.Parent = hit
		attachment.WorldCFrame = (humrp.CFrame * CFrame.new(0,0,-mag))
		attachment.Visible = true
		attachment.Name = "WallClimb"


		local BodyVelocity = Instance.new("BodyVelocity")
		BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		BodyVelocity.Velocity = Vector3.new(0,0,0)
		BodyVelocity.P = math.huge
		BodyVelocity.Parent = humrp
		BodyVelocity.Name = "Climb"
		
		local BodyGyro = Instance.new("BodyGyro")
		BodyGyro.CFrame = CFrame.new(Vector3.new()-surface)
		BodyGyro.D = 0
		BodyGyro.P = 0
		BodyGyro.MaxTorque = Vector3.new(0,0,0)
		BodyGyro.Parent = humrp 
		
			
		Debris:AddItem(BodyVelocity, 10)
		Debris:AddItem(BodyGyro, 10)
		wait(10)
		Climbing = false
		hum.PlatformStand = false
		print(Climbing)
		end
	end

Looks fine in the video. What exactly is going wrong? Have you tried forcing the player to face the wall during the climb? At least their body.

1 Like

Uh, no how would I do that exactly?

So when they touch the wall to start climbing. Use CFrames to rotate their body to face the wall.

Oh I did that, I used a body gyro to rotate the players humanoid root part

I’m not sure that works the same way. BodyGyro is usually for stabilization or making something maintain an orientation. You may not need to do any of that though. What exactly is the issue your having with your script, can you elaborate on that?

Basically I raycast to see if a wall is in front and the position is good and everything its just that bug where sometimes I go off the wall and if im not directly facing the wall it doesn allign me right

Have a look at this: https://developer.roblox.com/en-us/articles/Understanding-CFrame

You can use that to figure out how to go about forcing the player using the CFrame to always directly face the wall. I don’t want to give you incorrect code but you can get the position and vector details you need using the wall and character CFrames.

1 Like

Alright ill take a look thanks!