Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with rotation?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.