2d platformer, help on climb function

Hi!

So i am working on this 2d sidescroller game where you only can move left or right, and so far i got it working. Now i also want to let the humanoid climb ladders etc. when those are climeable offcourse. Anybody got any thoughts on how to make that work? i tried placing a truss just there so the humanoid still “bumps” on it and goes climbing but thats not the solution im aiming for since than your climbing on the side’s and have to jump off if you dont want to climb.

So im looking for this:
Humanoid can freely walk past the climeable and if the player wants to climb he/she press w (for example) to start climbing.

Controlscript so far:

        local player = game.Players.LocalPlayer
        local RunService = game:GetService("RunService")
        local ContextActionService = game:GetService("ContextActionService")
         
        local jumping = false
        local leftValue, rightValue = 0, 0
         
        local function onLeft(actionName, inputState)
        	if inputState == Enum.UserInputState.Begin then	
        		leftValue = 1
        	elseif inputState == Enum.UserInputState.End then
        		leftValue = 0
        	end
        end
         
        local function onRight(actionName, inputState)
        	if inputState == Enum.UserInputState.Begin then
        		rightValue = 1
        	elseif inputState == Enum.UserInputState.End then
        		rightValue = 0
        	end
        end
         
        local function onJump(actionName, inputState)
        	if inputState == Enum.UserInputState.Begin then
        		jumping = true
        	elseif inputState == Enum.UserInputState.End then
        		jumping = false
        	end
        end
         
        local function onUpdate()
        	if player.Character and player.Character:FindFirstChild("Humanoid") then
        		if jumping then
        			player.Character.Humanoid.Jump = true
        		end
        		local moveDirection = rightValue - leftValue
        		player.Character.Humanoid:Move(Vector3.new(moveDirection,0,0), false)
        	end
        end
         
        RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, onUpdate)
         
        ContextActionService:BindAction("Left", onLeft, true, "a", Enum.KeyCode.Left, Enum.KeyCode.DPadLeft)
        ContextActionService:BindAction("Right", onRight, true, "d", Enum.KeyCode.Right, Enum.KeyCode.DPadRight)
        ContextActionService:BindAction("Jump", onJump, true, Enum.KeyCode.Space, Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)

image to explain the situation a bit

I have searched the forums but didnt found anything about this.
Thanks all for reading!

2 Likes

you can use magnitude:

If the player presses w, the script will detect if the player is in a specific magnitude from the truss. And if they are, they climb it

3 Likes