Heya! I've been searching for the past couple of days with nothing on how to make a wall run script. All of my attempts failed and there was no tutorial on how to do it.
Here is my code:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
while char and wait() do
local hrp = char:WaitForChild("HumanoidRootPart")
local rightRay = workspace:Raycast(hrp.Position, hrp.CFrame.lookVector * 300)
local leftRay = workspace:Raycast(hrp.Position, -hrp.CFrame.lookVector * 300)
if not rightRay or not leftRay then return end
if rightRay.Instance then
print(rightRay.Instance.Name.." | "..tostring(rightRay.Instance.Position))
end
if leftRay.Instance then
print(leftRay.Instance.Name.." | "..tostring(leftRay.Instance.Position))
end
if rightRay.Instance and leftRay.Instance then
if hrp:FindFirstChildOfClass("BodyVelocity") then
hrp:FindFirstChildOfClass("BodyVelocity"):Destroy()
end
local rr_mag = (rightRay.Instance.Position - hrp.Position).magnitude
local lr_mag = (leftRay.Instance.Position - hrp.Position).magnitude
local min = math.min(rr_mag, lr_mag)
print(rightRay.Instance.Name, rightRay.Normal)
local chosenRay = nil
if min == rr_mag then chosenRay = rightRay else chosenRay = leftRay end
if chosenRay.Normal.Y ~= 0 then return end
local bv = Instance.new("BodyVelocity", hrp)
bv.MaxForce = Vector3.new('inf','inf','inf')
bv.Velocity = chosenRay.Normal:Cross(Vector3.new(0, 1, 0))
end
end
end)
end)
Please, please can somebody help me?
(Also, I don't want EgoMoose's Gravity Controller)
