Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(Wall Walking) Character Cannot Walk Straight Up?

Asked by
Nikkulaos 229 Moderation Voter
6 years ago

I am making a wall walking script, but my character only seems to be able to walk on parts that are not straight up.

It can walk on a 85 degree angle, but not on a 90 degree angle. It will just fall off. If anyone can find a solution it will be greatly appreciated! Thanks!

local player = game.Players.LocalPlayer;
local character = player.CharacterAdded:wait();

local torso = character:WaitForChild("Torso");
local hrp = character:WaitForChild("HumanoidRootPart");
local hum = character:WaitForChild("Humanoid");

local root = hrp:WaitForChild("RootJoint");
local rootC0 = root.C0;
local rootC1 = root.C1;

function update()
    local ray = Ray.new(hrp.CFrame.p, torso.CFrame:vectorToWorldSpace(Vector3.new(0, -5, 0)));
    local hit, pos, normal = game.Workspace:FindPartOnRay(ray, character);
    if hit then
        local cross = Vector3.new(0, 1, 0):Cross(normal);
        cross = cross.magnitude == 0 and Vector3.new(1) or cross;
        local angle = math.acos(normal:Dot(Vector3.new(0, 1, 0)));

        local lateral = hrp.CFrame - hrp.CFrame.p;
        local cf = CFrame.new(pos + normal * 3) * CFrame.fromAxisAngle(cross, angle) * lateral;

        root.C0 = hrp.CFrame:inverse() * (cf * rootC1);
    else
        root.C0 = rootC0;
    end;
end;

game:GetService("RunService").RenderStepped:connect(update);

Answer this question