Hey, I’ve got a turret that rotates on a HingeConstraint. The HingeConstraint doesn’t actually move the turret, instead I use a LinearVelocity that points the model in whatever direction the player’s mouse is pointed at. The HingeConstraint merely limits what axis it can rotate on, and to what maximum angles. However, using this method, the rotation of the model is updated almost instantaneously, but I want to make it rotate slower.
Using my current methods, is there any way to forcefully slow down a hinge?
To keep using your current method, I’d use vector3s’ lerp method to calculate a rotation to spin to and set the linear velocity constraint’s direction to that returned value. Any time the player update’s their direction, I’d restart the timer with a new lerp. You can put the lerp into a for loop with its increment defining how fast the turret spins for each heartbeat. The first idea of how you’d restart the timer that came to mind is to put that timer into a coroutine and close the coroutine every single time the player moves their mouse. I’m sure there’s a better way, though.
That said, this method is needlessly complex. I think using the hinge constraint with its ActuatorType property set to servo would be more optimal. It eliminates the extra constraint you’re using and you get to directly control the maximum speed at which your turret spins through its AngularSpeed property. After that, all you need to do is calculate the angle to rotate to.
Could you provide an example of the method you stated above?
I have tried doing so, but was unable to figure out how I’d translate the player’s mouse hit position into an angle that can be used by the HingeConstraint. Researching was of little help, the topic doesn’t seem to be covered very well.
Since you’re using the mouse class instead of user input service, you can use its UnitRay property to get the direction the mouse is aiming at through “Mouse.UnitRay.Direction”. After converting it to degrees by multiplying it by 180, you can just plug the y component into the hinge constraint. If 180 doesn’t do what I expect it to do, you can try 360 instead.
Another thing to keep in mind is the orientation of the hinge constraint. It might lead to some unexpected behavior if you have its orientation offset from the world. That would lead to a disconnect between it and the UnitRay’s direction.
How are you using a LinearVelocity to do rotation?
If you’re using an AngularVelocity, you can adjust the AngularVelocity value to control the rotation speed (though you’re probably not using one). If you’re using an AlignOrientation, you can just adjust the MaxAngularVelocity.
You can also use a Motor6 to control the angle of the turret, which has a convenient property MaxVelocity (measured in radians per second).
I would recommend using an AlignOrientation for your setup if the turret is affected by physics (e.g. it can be stopped by a wall in the way) otherwise I’d recommend either an AlignOrientation or Motor6.
Currently, the LinearVelocity applies a force to the turret in whatever direction the mouse’s hit position is, which rotates the part to face that direction due to the HingeConstraint keeping it in place.
I might try using AlignOrientation as you suggested.