local ray = Ray.new(humanoidRootPart.Position, humanoidRootPart.CFrame.LookVector*10)
local part, position, surfaceNormal = workspace:FindPartOnRay(ray)
to stay on the wall:
local ray = Ray.new(humanoidRootPart.Position, (humanoidRootPart.CFrame*CFrame.Angles(math.pi,0,0)).UpVector*10)
local _, position, surfaceNormal = workspace:FindPartOnRay(ray)
this would fling the humanoidrootpart or glitch it lmao
Ur basically teleporting the central ‘chest’ of the character to the ground.
Use some offsets maybe.
I used your lines of code and it started tping me in the air
local RootPart = script.Parent.HumanoidRootPart
local ray = Ray.new(RootPart.Position, RootPart.CFrame.LookVector*10)
local part, position, surfaceNormal = workspace:FindPartOnRay(ray)
local ray = Ray.new(RootPart.Position, (RootPart.CFrame*CFrame.Angles(math.pi,0,0)).UpVector*10)
local _, position, surfaceNormal = workspace:FindPartOnRay(ray)
while wait() do
RootPart.CFrame = CFrame.new(position, position + surfaceNormal)
end
while game:GetService("RunService").Heartbeat:Wait() do
local part, position, surfaceNormal;
if not onWall then
local ray = Ray.new(RootPart.Position, RootPart.CFrame.LookVector*10)
part, position, surfaceNormal = workspace:FindPartOnRay(ray)
if part then
onWall = true
continue
end
else
local ray = Ray.new(humanoidRootPart.Position, (humanoidRootPart.CFrame*CFrame.Angles(math.pi,0,0)).UpVector*10)
part, position, surfaceNormal = workspace:FindPartOnRay(ray)
if not part then
onWall = false
continue
end
end
humanoidRootPart.CFrame = CFrame.new(position, position + surfaceNormal)
end```
Im sorry I never realised you were making like, a custom character controller. The humanoid cannot simply stick to walls (correct me if I’m wrong), you have to make your own custom character controller. I recommend you learn more about algebra math, from which a lot- is needed to make this kind of controller. You cannot simply displace the character and expect it to move normally. It’ll glitch/fling because you’re teleporting the player and not actually considering movement controls, animation and physics.
Simply put, this is no method to make a character to ‘stick’ to walls.
The method to this is much deeper than displacing the humanoid root part, and involves more than that. This method is basically teleporting the player to a wall, and not actually sticking it onto a wall.
In addition to this, while wait() do is not efficient in ANY code.
while game:GetService("RunService").Heartbeat:Wait() do
local downRay = Ray.new(rootPart.Position, Vector3.new(0, -10, 0))
local _, _, normal = workspace:FindPartOnRayWithIgnoreList(downRay, {localCharacter})
rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + normal)
end