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

How do you manually rotate a humanoid?

Asked by
ItsMeKlc 235 Moderation Voter
7 years ago

How do you manually rotate a humanoid? I'm trying to lock my player's walking directions to 2 main axis (forward/backwards, side to side). Not entirely sure how to go about it. Would love input!

1 answer

Log in to vote
0
Answered by 7 years ago

I assume your looking for your player to move on a 2D Plane This script limits the player to only be able to move on 2 Axis. Key components are Object Mass, Body Position, and Vector3

function GetMass(object)
    local mass = 0
    if pcall(function() return object:GetMass() end) then
        mass = object:GetMass()
    end
    for _,child in pairs(object:GetChildren()) do
        mass = mass + GetMass(child)
    end
    return mass
end

function onPlayerRespawned(newPlayer)
    wait()
    local torso = newPlayer.Character.Torso 
    local bp = Instance.new("BodyPosition")
    bp.Name = "TwoD"
    bp.position = torso.Position
    bp.P = 1000000
    bp.D = 1000
    bp.maxForce = Vector3.new(0, 0, 1000000)
    bp.Parent = torso
    local bf = Instance.new("BodyForce")
    bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
    bf.Parent = torso
    newPlayer.Character.Humanoid.WalkSpeed = 24
    script.LocalScript:Clone().Parent = torso.Parent
    newPlayer.Character.DescendantAdded:connect(function()
        bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
    end)
    newPlayer.Character.DescendantRemoving:connect(function()
        bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
    end)
end

function onPlayerEntered(newPlayer)
    if newPlayer.Character then
        onPlayerRespawned(newPlayer)
    end
    newPlayer.Changed:connect(function (property)
        if (property == "Character") and newPlayer.Character then
            onPlayerRespawned(newPlayer)
        end
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

0
Not exactly. I basically want to player to only be able to walk 0, 90, 180, 270 ItsMeKlc 235 — 7y
Ad

Answer this question