Make turret face mouse position

What’s the best way to go about making the turret aim at the mouse position?

Currently I’m using body gyro inside the turret with cylindrical constraints and then making
the body gyro, every heart beat, to look at the mouse position, like so:

Remote.OnServerEvent:Connect(function(player, mouse)
	gyro.CFrame = ,, mouse.Y, mouse.Z) )

The remote is wrapped in a run service function in a local script.

How would I do this using align orientation?

Or is there a better way to rotate things? like CFrame?

I want to change methods because body gyro can be very buggy at times also its deprecated.

Use CFrame.LookAt.

gyro.CFrame = CFrame.lookAt(turret.Position , mouse.Hit.Position )

Also you should use UserInputService instead of mouse.

1 Like

I don’t want to use gyro because its deprecated. Are there any other methods?

Maybe check and make sure the axis is correct? I can’t give you a detailed explanation because you don’t provide any video of this alleged “glitch” of the gyro?

Oh I thought the part name was gyro mb. So basically change the turrent’s cframe to that.

Turrent.CFrame = CFrame.lookAt(turret.Position , mouse.Hit.Position )

There is no “glitch”, I’m simply looking for another way to rotate the turret that doesn’t include body gyros, because they are deprecated.

Try this:

Turret.CFrame =, mouse.Hit.Position)

Would this work with cylindrical constraints?

No. it does not work with cylindrical constraints, you will need a regular part to do this

I’m looking for a method which works with constraints as the turret will be attached to a vehicle.

How could I make this work for 2 parts? like 1 part controls the x and z axis, while another part controls the y axis?

You should try to union them⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

I don’t want the entire turret to move on the y axis, only the actual cannon part should move on the y axis