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

How to make player rotate to the slope they are walking on?

Asked by 7 years ago
Edited 7 years ago

To explain what I'm trying to do;

A humanoid for example walks up a ramp. The humanoid acts as if hes still walking on flat ground trying to walk through the ramp instead of walking up the ramp.

I want to prevent this.

local mouse = game.Players.LocalPlayer:GetMouse()
local moveModel = game.Players.LocalPlayer.Character;
-- don't detect the model we're moving
mouse.TargetFilter = moveModel


local c = moveModel;
local hrp = c:WaitForChild("HumanoidRootPart")
local j = hrp:WaitForChild("Root Hip")
local orig = j.C0

function placeAtMouse()
    -- make sure the mouse is pointing at something
    if mouse.Target then
        -- where we cast our ray from (shifted slightly up so the ray will hit the surface we're hovering)

    local point = moveModel.Torso.Position;

    local ray = Ray.new(
                moveModel.Torso.Position,
                Vector3.new(0, -10, 0)
            )
local hit, pos, normal = workspace:FindPartOnRay(ray, moveModel)
    if hit ~= nil then
        local origin = point + Vector3.new(0, 0.1, 0)

        -- cast our ray and get our normal, which is a unit vector
        local ray = Ray.new(origin, Vector3.new(0, -1, 0))

        -- get the perpendicular vector and the angle between the two
        local cross = Vector3.new(0, 1, 0):Cross(normal)
        local angle = math.asin(cross.magnitude) -- division by 1 is redundant
        local dude = script:WaitForChild("AngleValue")
        dude.Value = angle
    print(angle)
local savedCFrame = moveModel.Torso.Orientation;




j.C0 = orig*CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle)


        --moveModel.Torso.CFrame = 
            --(CFrame.new(moveModel.Torso.Position)) -- position
            --* CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle) -- angle, cross must not be Vector3.new()


    local newCFrame;

    end
    end
end

-- check every frame
game:GetService("RunService").RenderStepped:connect(function()
    placeAtMouse()
end)
0
well please desscribe you question explain what you want. Tsb102403 -9 — 7y
0
How maybe could find the part he is walking on by using a ray. Then, match the orientation of the part using a BodyGyro. But this wouldn't work for wedges. Also might prevent you from rotating your player. Sorry if I miss understood your question. Just a thought. Bluemonkey132 194 — 7y

1 answer

Log in to vote
-2
Answered by 7 years ago

OHHHHH DERP. In humanoid properties. Change the max slope angle to what ever you want! (Make it higher)

0
omg im sorry i read the comments on community chat you explained. In real life... Yeah idk thats tough mate Tsb102403 -9 — 7y
0
The maximum slope angle is 89.9. The default is just 89. Won't help. OriginalPacificalSun 0 — 3y
Ad

Answer this question