#Gun stabilizer

1 messages · Page 1 of 1 (latest)

robust minnow
#

Lets make this a thread

#

My hierarchy for the tank is:
Vehicle -> turret -> gun

#

The vehicle has the physics

gleaming rover
#

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?

robust minnow
gleaming rover
#

So okay, we make a random target then. Since it seems you currently don't have one.

robust minnow
#

Do you mean by target the value of targetX?

gleaming rover
robust minnow
#

It is abstract it's just a value.

gleaming rover
#
    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.

robust minnow
#

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.

gleaming rover
#

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.

robust minnow
#

Maybe the code is a little wrong right now 😄.

targetX is the rotation I would like the gun to stabilize to

gleaming rover
#

Hmm.

#

I was thinking about a world of tanks style game, or a warthunder type game. Seems I misunderstood then.

robust minnow
#

World of Tanks and War Thunder both have gun stabilizers and are in 3D

#

my game is also in 3D

#

I'm fixing the code right now, because it's a little confusing. Traverse and stabilization are different things