How do I make the turret head turn to the mouse location?

I am in the process of making the turret head of my warship to turn and face the mouse position using body gyro (for the smooth following action when you move your mouse) and a hinge for rotation.? (Idk if the hinge is part of the problem or not)

The issue is that I have no idea how to do it properly and I am stuck.

I have tried using the methods on Youtube and DevForum like bodygyro.CFrame = CFrame.new(mouse.Hit.Position.X, part.CFrame.Y, mouse.Hit.Position.Z)
but with no success…

the turret head is a union and Idk if that will affect the turning.
https://gyazo.com/917d9285ff7583645439bce40fea2df9
https://gyazo.com/650cdfb5dbdfd98ba4714dd76869d23d

Any help is appreciated! I will provide as much info as I can!

1 Like

Hello! You’re doing wrong CFrame you CFrame shoud look like this

local Pos = Vector3.new(mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z)
CFrame.new(TurretHead.Position,Pos)

I hope it will works!

I will try it right now! 3000000

the union is spinning by itself with body gyro and hinge

1 Like

Finally got it to work! Big thanks to @EsplishData for showing me my mistakes. For any future viewers, here is what I did:

local invisBox = game.Workspace.testHeadmodel.Invisbox
local mouse = game.Players.LocalPlayer:GetMouse()
local bodygyro = invisBox.BodyGyro

while wait() do
bodygyro.CFrame = CFrame.new(bodygyro.Parent.Position ,Vector3.new(mouse.Hit.Position.X, invisBox.Position.Y, mouse.Hit.Position.Z) )
end
1 Like