✓ Accepted answer
There was actually an article about this in the blog that may help. You can find it here
One way to do it is to use direction. Here is the code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local runService = game:GetService("RunService")
humanoid.AutoRotate = false
runService:BindToRenderStep("MouseMovement", Enum.RenderPriority.Input.Value, function()
local direction = mouse.Hit.p - torso.Position
direction = direction * Vector3.new(1, 0, 1)
torso.CFrame = CFrame.new(torso.Position, torso.Position + direction)
end)
So first I define my variables: player, mouse, character, etc.
Then I disable AutoRotate, a property of the humanoid.
Then I bind a function to RenderStep. You will get the same results if you use a while true do loop, but this makes it a bit more smoother.
In the function, we get the direction by subtracting the mouse's position and the torso's position. Then we multiply it by `Vector3.new(1, 0, 1) to get rid of the why value, this is to prevent the player from looking upwards. Finally we set the torso's CFrame to face the direction of the mouse.
3 comments
Thanks! ,though i wanted it to point upwards too,but i got the answer i wanted.
If you want to make it point upwards too, remove line 18.
Also,how can i end the script so it wont point to the mouse anymore?