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

What is the best way to rotate a player?

Asked by 7 years ago

Hey

Trying to rotate a character

Here is the code I have so far which sucessfully rotates the player 45 degrees on the y axis

game.Players.PlayerAdded:connect(function(ply)
    game.Workspace:WaitForChild(ply.Name)
    local character = game.Workspace[ply.Name]
    character.Humanoid.AutoRotate = false
    while wait() do
        character.Torso.CFrame = CFrame.Angles(0,math.rad(45),0) + character.Torso.CFrame.p
    end
end)

However, when rotating 45 degrees on the x axis the character is always trying to rotate itself back to standing up

game.Players.PlayerAdded:connect(function(ply)
    game.Workspace:WaitForChild(ply.Name)
    local character = game.Workspace[ply.Name]
    character.Humanoid.AutoRotate = false
    while wait() do
        character.Torso.CFrame = CFrame.Angles(math.rad(45),0,0) + character.Torso.CFrame.p
    end
end)

If there were some way to stop the character from trying to auto flip itself back to normal orientation then that would fix the problem. I have tried turning off autorotate but this only fixed the problem on the y axis. I have also tried using bodygyro, but you can't set a particular rotation with that so that is not ideal.

Any help will be greatly appreciated

0
Well you could use BodyGyro, but you'd have to update it's velocity constantly. You could anchor the character temporarily as well. Personally, I've also been looking for a way to make characters walk an angle, haven't found it yet though, so I wish you luck. Tomstah 401 — 7y
0
I've already turned off auto rotate in the script and it only fixes rotations on the y axis. I will keep posted if I find an answer. 123marble 61 — 7y

2 answers

Log in to vote
0
Answered by 3 years ago

Im not a good scripter, but based on my knowledge, while wait() do is a much slower process to loop stuff. Instead, you would need to use Heartbeat, which is faster.

game.Players.PlayerAdded:connect(function(ply)
    game.Workspace:WaitForChild(ply.Name)
    local character = game.Workspace[ply.Name]
    character.Humanoid.AutoRotate = false
    game.RunService.Heartbeat:Connect(function() 
        character.Torso.CFrame = CFrame.Angles(math.rad(45),0,0) + character.Torso.CFrame.p
    end)
end)

Ad
Log in to vote
0
Answered by 2 years ago

I have the same problem as well.

To "temporarily" overcome this problem, I used

humanoid.Sit = true
-- or
humanoid.PlatformStand = true

The major down side to this solution is that humanoids have a "timer" to get up, so it isn't the best solution for me. It can work for your code though,

0
Sorry for posting 4 years later arxlfox 0 — 2y

Answer this question