So I’m trying to make a climbing script, but for the first step of doing that, I need a player to latch onto a wall.
My problem is, I don’t know how to force a player to face a surface. I’ve tried raycasting and using a bodygyro to make them face it, but it lets me tilt away a bit and doesn’t work at all if I’m shift-locked.
I also don’t know how to force the player to cling to a wall either.
Remote.OnServerEvent:Connect(function(Player,Input)
-- Variables --
local UserID = Player.UserId
local Char = Player.Character or Player:WaitForChild("Character")
local Humanoid = Char.Humanoid
local HumanoidRootPart = Char.HumanoidRootPart
-- RAYCASTING STUFF --
local RayOrigin = HumanoidRootPart.Position
local RayDirection = HumanoidRootPart.CFrame.LookVector
local IgnoreList = {}
local CharDescendants = Char:GetDescendants()
for _, v in pairs(CharDescendants) do
if v:IsA("MeshPart") then
table.insert(IgnoreList,v)
end
end
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = IgnoreList
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
local RaycastResult = workspace:Raycast(RayOrigin,RayDirection*10,RayParams)
-- Incase it returns nil
if RaycastResult then
Laser.Position = Vector3.new(RaycastResult.Position.X,RaycastResult.Position.Y,RaycastResult.Position.Z)
-- Rotation/Gyro
local ClimbGyro = Instance.new("BodyGyro")
ClimbGyro.CFrame = CFrame.new(HumanoidRootPart.Position,RaycastResult.Position)
ClimbGyro.D = 100
ClimbGyro.MaxTorque = Vector3.new(1,1,1)*math.huge
ClimbGyro.P = 3000
ClimbGyro.Parent = HumanoidRootPart
wait(1)
ClimbGyro:Destroy()
end
print(RaycastResult)
end)