Turret orientation towards mouse position being upset by AngularVelocity constraint

I have made the turret of my tank rotate towards the players’ Mouse.Hit.Position only along the Y-Axis. It works fine while the vehicle is stationary or moving forward/backwards, but when the vehicle is turning this is offset for some reason.

https://gyazo.com/d46412340943e95fd81e7356e31ce76e.mp4

The vehicle uses a LinearVelocity for forwards/backwards movement and uses an AngularVelocity for turning. I can only assume this is happening because of the AngularVelocity but I have no clue how I would go about fixing this. I’ve double-checked a lot of things and I am sure that my math works. The problem persists whether I tween the rotation or not.

https://i.gyazo.com/50d57a4aa98f4c248ae86541b4a219b3.mp4

1 Like

Although it’s deprecated, I suggest using a body gyro, you can use body gyro to turn an object to a set orientation. You can either get one from Instance.new() or just finding it in the toolbox.

2 Likes

Keep in mind that body gyros only takes in CFrame values

1 Like

Ignoring the fact that its deprecated, what use would I have for it? I wouldn’t use a body mover / constraint to orient a part rigged to a model when I could just set a joints CFrame. My problem lies with the AngularVelocity constraint offsetting my joints rotation. Replacing the constraint with a BodyGryo wouldn’t change anything as they both accomplish the same thing.

1 Like

You may want to increase MaxTorque within AngularVelocity, as it looks like the angular constraint is lagging behind the mouse movement in reaction to change.

Increasing the MaxTorque will decrease the influence from the Linear Velocity in the system:

1 Like

The AngularVelocity constraint is being used to turn the entire vehicle.

https://gyazo.com/0bfd4a1e3ace2e927f260928b7f86a5b.mp4

The turret orientation lagging behind is a purposeful tween to make it look nice. The constraints MaxTorque is already set to math.huge and removing the tween from the turret has the same effect happening.

https://gyazo.com/be0fb8ec3cd1d6806e501e5a165bdac7.mp4

1 Like

why don’t you add the inverse of the current turning velocity to the turret’s target cframe to counteract the turning

1 Like

Although they do almost the same things, bodyGyro has power and more importantly, dampening, You can turn the power really high so other velocities don’t effect it, then turn the dampening up to retain the smooth rotation.

The best solution I’ve found so far is to simply ditch the tween in favor of lerping the joints CFrame. I still don’t know why the tween struggled to keep itself oriented the right way, but lerping the CFrame towards the new Mouse.Hit seems to work good enough.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.