Hi,
I am working on wallrunning and I want the player to lock on the wall when they wallrun on it, so they aren’t able to move out.
How would I do this?
function Movement.Wallrun(self: ClassType, Humanoid, Root)
local isGrounded = if Humanoid.FloorMaterial == Enum.Material.Air then false else true
local velocity = Root.AssemblyLinearVelocity.Magnitude
if self.previousWall ~= nil then
local LeftWallCheck = WallrunFuncs[1](Root, PlayerSettings.WallrunRayLength, self.wallrunParameters) :: RaycastResult
local RightWallCheck = WallrunFuncs[2](Root, PlayerSettings.WallrunRayLength, self.wallrunParameters) :: RaycastResult
local Result = LeftWallCheck or RightWallCheck
if self.previousWall == Result.Instance and Humanoid:GetState() == Enum.HumanoidStateType.Freefall or not isGrounded then
print("Player tried to wallrun while freefalling on previous wall")
return
end
end
task.spawn(function()
WallrunUpdate = RunService.RenderStepped:Connect(function(deltaTime: number)
local LeftWallCheck = WallrunFuncs[1](Root, PlayerSettings.WallrunRayLength,self.wallrunParameters) :: RaycastResult
local RightWallCheck = WallrunFuncs[2](Root, PlayerSettings.WallrunRayLength,self.wallrunParameters) :: RaycastResult
local Result = LeftWallCheck or RightWallCheck
if Result and velocity >= 21 then
self.isWallrunning = true
WallrunFuncs[4](Result.Position)
Root.AssemblyLinearVelocity = Vector3.new(Root.AssemblyLinearVelocity.X,-1,Root.AssemblyLinearVelocity.Z)
self.previousWall = Result.Instance
elseif not Result or velocity < 21 or Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
self.isWallrunning = false
if WallrunUpdate then
WallrunUpdate:Disconnect()
end
end
end)
end)
end