Bodygyro Continues to Rotate to Face Mouse

You can write your topic however you want, but you need to answer these questions:

  1. I am working on a tank turret system that follows the mouse.

  2. Because I am using a body gyro on render stepped the body gyro keeps trying to face the mouse even if it is already perfect on the mouse.

  3. I have tried 3 solutions mainly. The first is moving to a WASD turret which worked fine but is undesirable as people didn’t seem to like WASD. The second is using mouse.Move which worked to an extent but would make the turret rotate weirdly as it would only go to the previous position of the mouse. Lastly, I tried getting the distance between a starting and moved the position of the mouse every render stepped which did not work at all.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

RunService.RenderStepped:Connect(function()
    if camera.CFrame.Position ~= Mouse.Hit.Position then
    Mouse.TargetFilter = vehicle
    Tool.Important.Events.Turn:FireServer(Mouse.Hit.Position)
    end
end)```

Client


```lua
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.Body.Sight.HingeConstraint.TargetAngle = vehicle.GunGyro.HingeConstraint.CurrentAngle

end

Tool.Important.Events.Turn.OnServerEvent:Connect(Turn)```

Server

Just combine both mouse.Moved and bodygyro to destroy and create it

1 Like

Could you please be a bit more specific? I think I get what you mean but im not entirely sure. Are you saying to create and destroy a body gyro everytime the mouse is moved?

1 Like