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

How can I make the Character face the Mouse?

When I used BodyGyro to try and make my Character face the mouse whenever I would point the mouse below me or above me it would always shake. I don't understand how I can fix this so i'm asking for help. If there is a better way to do it even with BodyGyro please explain to me how it can be done. Thank you for helping me. :)

1 answer

✓ Accepted answer

You can use CFrame. It gets buggy on the Y axis, so we might just want to ignore the Y axis when changing the direction of the player. We will be using the players mouse, CFrame, and a few other things. (You can do this on the client since client movement is replicated to the server)

If you have any questions about my code let me know in the comments on this post.

local runService = game:GetService("RunService")
local players = game:GetService("Players")
local client = players.LocalPlayer
local mouse = client:GetMouse()

local character = client.Character or client.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local function faceMouse()
	humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, Vector3.new(mouse.Hit.p.X, humanoidRootPart.Position.Y, mouse.Hit.p.Z))
end

runService.Heartbeat:Connect(faceMouse)

2 comments

0

Is there anyway to turn this off without Disabling the script?

0

@GG, omg im literally 20 days late. Yes use a variable and check inside of faceMouse() function

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