I would like to make a simple wall climbing system/custom client object for a JToH tower that allows the player to climb on certain walls.
I can’t seem to make sense of the scripts I’ve seen so I want to make a system that’s based on the JToH 5.4 kit and for it to be able to be scripted by a beginner/intermediate scripter like me.
I’ve tried using other people’s scripts and trying to port them over to the JToH kit.
You can achieve this by using raycasting to detect walls and setting the player’s movement accordingly.
Create a new LocalScript in StarterPlayerScripts and name it WallClimbing
My Approach
-- Constants
local RAYCAST_DISTANCE = 4
local MAX_CLIMB_ANGLE = 70
-- Variables
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local isClimbing = false
-- Raycast function
local function raycast(direction)
local origin = character.HumanoidRootPart.Position
local ray = Ray.new(origin, direction * RAYCAST_DISTANCE)
local part, hitPosition, normal = workspace:FindPartOnRay(ray, character)
return part, hitPosition, normal
end
-- Check if the player is facing a wall
local function checkForWall()
local direction = character.HumanoidRootPart.CFrame.LookVector
local part, _, normal = raycast(direction)
if part and part.CanCollide and normal.Y < 0.2 then
local angle = math.deg(math.acos(normal.Y))
if angle <= MAX_CLIMB_ANGLE then
return true
end
end
return false
end
-- Climb up the wall
local function climbUp()
isClimbing = true
humanoid.PlatformStand = true
while isClimbing and checkForWall() do
local direction = character.HumanoidRootPart.CFrame.LookVector
local _, hitPosition, normal = raycast(direction)
local targetPosition = hitPosition + normal * 3
local velocity = (targetPosition - character.HumanoidRootPart.Position) / 0.1
character.HumanoidRootPart.Velocity = velocity
wait(0.1)
end
isClimbing = false
humanoid.PlatformStand = false
end
-- Detect if the player presses the spacebar while facing a wall
local function onInput(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space and not gameProcessed then
if checkForWall() then
climbUp()
end
end
end
-- Connect the input function to the UserInputService
game:GetService("UserInputService").InputBegan:Connect(onInput)
My approach works by checking if the player is facing a wall within a certain angle of MAX_CLIMB_ANGLE. If a wall is detected, the script enters a climbing state where the player’s PlatformStand property is set to true and the script constantly updates the player’s position to move them up the wall. They can exit the climbing state by releasing the spacebar or moving away from the wall.
Additionally, you can customize RAYCAST_DISTANCE and MAX_CLIMB_ANGLE constants to adjust the sensitivity of the system.