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

Help with rotation?

Asked by 10 years ago

I have this script:

player = game.Players.LocalPlayer
mouse = player:GetMouse()
char = player.Character
while wait() do
    local dir = (mouse.Hit.Z - char.Torso.CFrame.Z) * 1000
    local dir2 = (mouse.Hit.X - char.Torso.CFrame.X) * 1000
    char.Torso.CFrame = CFrame.new(char.Torso.CFrame.p,Vector3.new(dir2,0,dir))
end

It is supposed to rotate the player to the direction the mouse is facing. It works, but, it is very glitchy(the player shakes a lot when you move). How would I make it smooth?

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

You can make the wait run in smaller increments with RunService using RenderStepped.

player = game.Players.LocalPlayer
mouse = player:GetMouse()
char = player.Character
RS = game:GetService("RunService")
while true do
    local dir = (mouse.Hit.Z - char.Torso.CFrame.Z) * 1000
    local dir2 = (mouse.Hit.X - char.Torso.CFrame.X) * 1000
    char.Torso.CFrame = CFrame.new(char.Torso.CFrame.p,Vector3.new(dir2,0,dir))
    RS.RenderStepped:wait()
end
Ad

Answer this question