How to make a wall run system

I know this is something I can figure out on my own but it’s quite complex for me now,

The thing I want to make is a wall Run system. I thought This code would work but soon I figured out that going the opposite direction of a part makes the character do things that I don’t intend on doing.

The plan,

  • Players Character would stick and slide the walls no matter of it’s opposite or not
  • How to find the relative positions of a part
  • How can I make this good.

The Script is in StarterCharacterScripts as a LocalScript

local RunServ = game:GetService("RunService") 
local RootPart = script.Parent:WaitForChild("HumanoidRootPart")

local rayP = RaycastParams.new()
rayP.FilterDescendantsInstances = {script.Parent, workspace.Baseplate}
rayP.FilterType = Enum.RaycastFilterType.Blacklist

local IsGoing = false

RunServ.RenderStepped:Connect(function()
	local Dir = (RootPart.CFrame * CFrame.Angles(0, math.rad(90),0)).LookVector * 3
	local Dir2 = (RootPart.CFrame * CFrame.Angles(0, math.rad(-90),0)).LookVector * 3
	local leftRes = workspace:Raycast(RootPart.Position, Dir, rayP)
	local rightRes = workspace:Raycast(RootPart.Position, Dir2, rayP)
	if leftRes and IsGoing == false then
		IsGoing = true
		local VelFind = RootPart:FindFirstChild("BodyVelocity")
		if VelFind then
			VelFind.P = 5000
		else
			local Vel = Instance.new("BodyVelocity")
			Vel.P = 5000
			Vel.Velocity = Vector3.new(20,0,0)
			Vel.Parent = RootPart
		end
		
		RootPart.CFrame = CFrame.new(leftRes.Position.X,leftRes.Position.Y,leftRes.Position.Z) * CFrame.Angles(0, math.rad(leftRes.Instance.Orientation.Y - 90), 0) * CFrame.new(2,0,0)
		IsGoing = false
	elseif rightRes and IsGoing == false then
		IsGoing = true
		local VelFind = RootPart:FindFirstChild("BodyVelocity")
		if VelFind then
			VelFind.P = 5000
		else
			local Vel = Instance.new("BodyVelocity")
			Vel.P = 5000
			Vel.Velocity = Vector3.new(20,0,0)
			Vel.Parent = RootPart
		end

		RootPart.CFrame = CFrame.new(rightRes.Position.X,rightRes.Position.Y,rightRes.Position.Z) * CFrame.Angles(0, math.rad(rightRes.Instance.Orientation.Y - 90), 0) * CFrame.new(-2,0,0)
		IsGoing = false
	elseif IsGoing == false then
		local VelFind = RootPart:FindFirstChild("BodyVelocity")
		if VelFind then
			VelFind:Destroy()
		end
	end
end)
	


6 Likes

Maybe try using angled, invisible parts? Maybe try adding an AngularVelocity into the part if you want it to move your player downwards a little bit?

2 Likes

Instead of doing this, you can use a capsule collider to handle this. A capsule collider is just an invisible shape that handles colliding with objects. You can simply do

capsulCollider.Cframe.RightVector * 3

just a suggestion, as for your issue, I’ll have to come back later.

4 Likes

Thanks for the organisation tweek! I dont really know how to do that honestly

1 Like