I have a wallrunning script here that allows users to run and jump off of walls. Apparently I can only wallrun in the part’s facing direction instead of the direction I want, such as left or right. Here’s the code, maybe someone can help me out.
local player = game.Players.LocalPlayer
local char = script.Parent
local UIS = game:GetService("UserInputService")
local torso = char.Torso
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
local cam = workspace.CurrentCamera
local mouse = player:GetMouse()
hrp.CanCollide = true
torso.CanCollide = false
local rwall = hum:LoadAnimation(script:WaitForChild("RWallrun"))
local lwall = hum:LoadAnimation(script:WaitForChild("LWallrun"))
local rwallj = hum:LoadAnimation(script:WaitForChild("RWallJump"))
local lwallj = hum:LoadAnimation(script:WaitForChild("LWallJump"))
local standing = false
local midair = false
local pushing = false
local sliding = false
local wallrunning = false
local wall = nil
local bonked = false
local rolling = false
local ducking = false
local function SetAnimationSpeed(animationTrack, Aspeed)
animationTrack:AdjustSpeed(Aspeed)
end
local function onHumanoidStateChanged(old, new)
if new == Enum.HumanoidStateType.Landed then
end
end
local function checkStats()
if (hum.MoveDirection == Vector3.new(0,0,0)) then --Checking if standing still and on the ground.
standing = true
else
standing = false
end
if hum.FloorMaterial ~= Enum.Material.Air then
midair = false
else
midair = true
end
local rightray = Ray.new(hrp.Position, hrp.CFrame.RightVector * 2) --Walljump and wallslide stuff here
local rhit = workspace:FindPartOnRay(rightray, char)
local leftray = Ray.new(hrp.Position, hrp.CFrame.RightVector * -2)
local lhit = workspace:FindPartOnRay(leftray, char)
local frontray = Ray.new(hrp.Position, hrp.CFrame.LookVector * 2)
local fhit = workspace:FindPartOnRay(frontray, char)
local hit
if rhit and not lhit and not fhit then
hit = rhit
elseif lhit and not rhit and not fhit then
hit = lhit
elseif fhit and not rhit and not lhit then
hit = fhit
end
if (midair and lhit or rhit or fhit) then
if hit.CanCollide == false then return end
if hit.Parent.ClassName ~= "Part" then return end
if hit.Name == "Part" then
wallrunning = false
local jumpv = Instance.new("BodyVelocity")
jumpv.Parent = hrp
jumpv.MaxForce = Vector3.new(5e5, 5e5, 5e5)
if hit == rhit then
jumpv.Velocity = Vector3.new(0,15,0) + hrp.CFrame.RightVector * -35
rwallj:Play()
elseif hit == lhit then
jumpv.Velocity = Vector3.new(0,15,0) + hrp.CFrame.RightVector * 35
lwallj:Play()
end
game.Debris:AddItem(jumpv, 0.1)
return
end
if hit.ClassName ~= "Part" then return end
local gyro = Instance.new("BodyGyro")
gyro.Parent = hrp
gyro.MaxTorque = Vector3.new(9e+18, 9e+18, 9e+18)
gyro.P = 9e+18
gyro.D = 1000000
gyro.CFrame = hit.Parent.End.CFrame
game.Debris:AddItem(gyro, 0.01)
wall = hit
hum.AutoRotate = false
wallrunning = true
local slidev = Instance.new("BodyVelocity")
slidev.Parent = hrp
slidev.MaxForce = Vector3.new(5e5, 5e5, 5e5)
if hrp.Velocity.magnitude > 10 then
slidev.Velocity = Vector3.new(0,0,0) + hrp.CFrame.LookVector * hrp.Velocity.magnitude
else
slidev.Velocity = Vector3.new(0,0,0) + hrp.CFrame.LookVector * 35
end
if hum.Jump then
wallrunning = false
slidev:Destroy()
local jumpv = Instance.new("BodyVelocity")
jumpv.Parent = hrp
jumpv.MaxForce = Vector3.new(5e5, 5e5, 5e5)
if hit == rhit then
jumpv.Velocity = Vector3.new(0,15,0) + hrp.CFrame.RightVector * -35
rwallj:Play()
elseif hit == lhit then
jumpv.Velocity = Vector3.new(0,15,0) + hrp.CFrame.RightVector * 35
lwallj:Play()
end
game.Debris:AddItem(jumpv, 0.1)
end
game.Debris:AddItem(slidev, 0.001)
if hit == rhit then
rwall:Play()
lwall:Stop()
elseif hit == lhit then
lwall:Play()
rwall:Stop()
end
else
hum.AutoRotate = true
wallrunning = false
rwall:Stop()
lwall:Stop()
end
end
local function InputBegan(input, process)
if (process or not hum or hum:GetState() == Enum.HumanoidStateType.Dead) then
return;
end
if input.KeyCode == Enum.KeyCode.E then
end
if (input.KeyCode == Enum.KeyCode.LeftShift) then
end
if (input.KeyCode == Enum.KeyCode.Q) then
end
if (input.KeyCode == Enum.KeyCode.Space) then
end
end
local function InputEnded(input, process)
if (input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down) then
end
end
hum.StateChanged:Connect(onHumanoidStateChanged);
UIS.InputBegan:Connect(InputBegan)
UIS.InputEnded:Connect(InputEnded)
game:GetService("RunService").RenderStepped:Connect(checkStats)