How do I make the Character look at the mouse?

I’m trying to get the character to look at the cursor, but I’m not sure how. I tried using BodyGyros, which worked but was very sluggish. I even tried lowering the Dampening and increasing the P on the BodyGyro, but that didn’t help. I also attempted to use CFrame.lookat, but that did not work either. The character just rotated in an odd way.

3 Likes

Hmm… can you share your code so I can take a look at it?

2 Likes

Alright, here is my code

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local BodyGyro = Instance.new("BodyGyro", Player.Character.HumanoidRootPart)
BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
BodyGyro.D = 5
BodyGyro.P = 10^4
BodyGyro.CFrame = CFrame.new()

coroutine.resume(coroutine.create(function()
	while true do
		BodyGyro.CFrame = Mouse.Hit
		game:GetService("RunService").Heartbeat:Wait()
	end			
end))
1 Like

Instead of “Mouse.Hit”, use “Mouse.Position”

I don’t think that would work since it is a BodyGyro

What is your character doing now with your current code?

It is looking at the cursor, but it is very sluggish

To clarify what do you mean by sluggish?

Fixed it

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local BodyGyro = Instance.new("BodyGyro", Player.Character:WaitForChild("HumanoidRootPart"))
BodyGyro.MaxTorque = Vector3.new(0, math.huge, math.huge)
BodyGyro.D = 5
BodyGyro.P = 10^4
BodyGyro.CFrame = CFrame.new()

coroutine.resume(coroutine.create(function()
	while true do
		BodyGyro.CFrame = Mouse.Hit
		game:GetService("RunService").Heartbeat:Wait()
	end			
end))

It feels very choppy and laggy.

You could lerp it

BodyGyro.CFrame = BodyGyro.CFrame:Lerp(Mouse.Hit, 0.1)

This should help

1 Like