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

Player tries to climb over own Humanoid root part due to raycast?

Asked by 6 years ago
Edited 6 years ago

Hi, this right here is supposed to make a player rotate to the angle it is walking on. For some reason, if I run at least 16 walkspeed, the player tries to climb over its own HumanoidRootPart.

How do I stop this from happening?

local root = HumanoidRootPart:WaitForChild("Root Hip");
local rootC0 = root.C0;
local rootC1 = root.C1;

function update()
    -- not as great on steep slopes b/c it wants to climb its own Humanoid Root Part with the fixed direction of the way
    local direction = Vector3.new(0, -4, 0) --torso.CFrame:vectorToWorldSpace(Vector3.new(0, -4, 0));
    local ray = Ray.new(HumanoidRootPart.CFrame.p, direction);
    local hit, pos, normal = game.Workspace:FindPartOnRayWithIgnoreList(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 = HumanoidRootPart.CFrame - HumanoidRootPart.CFrame.p;
        local cf = CFrame.new(pos + normal * 3) * CFrame.fromAxisAngle(cross, angle) * lateral;

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

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

0
cancollide off the humanoidrootpart NsNidPL 41 — 6y
0
btw this is lua! u don't have to put ; behind every line! DanielDeJong3 158 — 6y
0
@NsNidPL CanCollide is off for the HumanoidRootPart JoeRaptor 72 — 6y
0
@NsNidPL Also, I am really sure that's not the problem. JoeRaptor 72 — 6y
View all comments (3 more)
0
Try to make the raycast ignore the humanoid root part SuperAndresZ_YT 202 — 6y
0
How do you make the ray ignore multiple things? JoeRaptor 72 — 6y
0
ray with ignore list Wafflecow321 457 — 6y

Answer this question