Issues with BodyGyro facing mouse

Hello devs, i’m currently having issues with bodyGyro. I was trying to make the bodyGyro face the mouse cursor position for a plane control system, but it’s not working as shown below.

Captura de tela 2024-03-27 132253

Script:

Events.Face.OnServerEvent:Connect(function(client,mouseHit) 
	if client == player then
	local mousePosition = mouseHit --Mouse.hit.p
	local directionPlane = (mousePosition - engine.Position).Unit

		local angle = math.atan2(-directionPlane.X, -directionPlane.Z)
		bg.CFrame = CFrame.new(directionPlane) * CFrame.Angles(angle, angle, angle)
	end
end)

Whats wrong with the script?
(I’m not the best at CFrames.)

Any help is appreciated.

CFrame has a LookAt method, which can also be used as a override in the constructor.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.