Body Gyro Will not Perfectly Align with the Mouse's Position

I would like to have my body-gyro’s face my mouse’s position exactly. The turret system of this tank relies on the bodygyro facing the mouse and feeding the hinge on that body gyro’s angle to a servo set to spin the turret.

The issue is the misalignment that occurs when the gun faces downwards. This is illustrated here:

I have mostly just tried(unsuccessfully) to trial and error with some of the positions and the properties of the gyro.

local function Turn(player, ToP, camera)
	vehicle.Body.Turret.TurretGyro.BodyGyro.CFrame = CFrame.lookAt(vehicle.Body.Turret.TurretGyro.Position, ToP)
	vehicle.Body.Turret.Turret.TargetAngle = vehicle.Body.Turret.TurretGyro.GyroHinge.CurrentAngle

	vehicle.GunGyro.BodyGyro.CFrame = CFrame.lookAt(vehicle.GunGyro.Position, ToP)
	vehicle.Body.gunhing.HingeConstraint.TargetAngle = vehicle.GunGyro.HingeConstraint.CurrentAngle
	vehicle.mgcon.HingeConstraint.TargetAngle = vehicle.GunGyro.HingeConstraint.CurrentAngle


	vehicle.Body.Sight.HingeConstraint.TargetAngle = vehicle.GunGyro.HingeConstraint.CurrentAngle

end

script.Parent.Parent.Important.Events.Turn.OnServerEvent:Connect(Turn)

ToP represents the mouse’s position.

1 Like