#Gun stabilizer
1 messages · Page 1 of 1 (latest)
Lets make this a thread
My hierarchy for the tank is:
Vehicle -> turret -> gun
The vehicle has the physics
Yeah, but currently you are making a new rotation, in world space, with (10, 0, 0) for example. And your gun will try to look at that. That ain't good.
What is the target rotation you want?
The rotation towards the target somewhere?
You can aim the gun up and down to certain extent. Up 20 degrees and down -10 degrees depends on the vehicle.
So okay, we make a random target then. Since it seems you currently don't have one.
Do you mean by target the value of targetX?
No, I mean somewhere like another tank, or a house. Somewhere you want to look.
It is abstract it's just a value.
private void Update()
{
targetX = Mathf.Clamp(targetX, MaxGunDepression, MaxGunElevation);
if (stabilize)
{
Vector3 stabilizeVector = new Vector3(targetX, 0, 0);
gunTransform.localRotation = Quaternion.RotateTowards(gunTransform.localRotation, Quaternion.Euler(stabilizeVector), verticalStabilizationSpeed * Time.deltaTime);
}
}
If you use this, and change the targetX in the inspector, it should change the rotation of the gun up and down of your gun.
yes it does
It works perfectly. But local rotation means that the gun is not stabilized, because it's not canceling the movement of the vehicle.
That's what I meant by your target rotation.
That's the thing that should cancel out the movement of the vehicle.
Currently you need to change/calculate your targetX to be that target.
What that number is, is up to you. That's my question.
Maybe the code is a little wrong right now 😄.
targetX is the rotation I would like the gun to stabilize to