Having a problem with my wall climbing movement velocity. Supposed to be moving them across the axis of the wall, but instead they just move randomly. Movement isn’t capped to the wall yet, either.
Here’s my code:
local RepStorage = game:GetService("ReplicatedStorage")
local Remotes = RepStorage.Remotes
local WallClimbingRemote = Remotes.WallClimbingInput
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char.Humanoid
local hrp = char.HumanoidRootPart
local playerIsClimbing = false
WallClimbingRemote.OnServerEvent:Connect(function(player, direction)
if player == plr then
if playerIsClimbing == true then
local velocity = hrp:FindFirstChild("LinearVelocity")
if velocity then
print('velocity found')
if direction == "Right" then
velocity.VectorVelocity = Vector3.new(90,0,0)
elseif direction == "Left" then
velocity.VectorVelocity = Vector3.new(-90,0,0)
end
velocity.MaxForce = 15000
end
end
end
end)
while wait() do
local wall = workspace.Wall
if not wall then continue end
if not hrp then continue end
if playerIsClimbing then continue end
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {char}
local direction = hrp.CFrame.LookVector*1.5
local raycastResult = workspace:Raycast(hrp.Position, direction, raycastParams)
if not raycastResult then continue end
if raycastResult.Instance then
if raycastResult.Instance == wall then
if not playerIsClimbing then
hrp.CFrame = CFrame.lookAt(raycastResult.Position, raycastResult.Position + Vector3.new(0,0,-0.15))
hum.PlatformStand = true
local alignPosition = Instance.new('AlignPosition')
alignPosition.Mode = "OneAttachment"
alignPosition.Parent = hrp
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = hrp
alignPosition.Position = raycastResult.Position
alignPosition.Attachment0 = attachment0
hrp.Orientation = Vector3.new(0,0,0)
hum.AutoRotate = false
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.MaxForce = 0
linearVelocity.Parent = hrp
local attachment0 = Instance.new('Attachment')
attachment0.Name = "VelocityObject"
attachment0.Parent = hrp
linearVelocity.Attachment0 = attachment0
playerIsClimbing = true
end
end
end
end
end)