V
V
varp52020-12-25 18:02:19
Unity
varp5, 2020-12-25 18:02:19

How can you limit the rotation of the cannon on a tank?

I can't figure out how to limit the rotation angle of the gun, the gun turns left and right, and if you don't set a limit, it will climb into the texture of the tank, how can this be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Almost, 2020-12-25
@Almost

1. Get the direction vector of the tank.
2. Get the direction vector of the gun.
3. When turning the gun, check the angle between the direction of the gun and the tank. If it is greater than the angle N, then do not turn the gun.

G
GFX Data, 2020-12-26
@ShockWave2048

float angle = Mathf.Clamp(angleSource, ANGLE_MIN, ANGLE_MAX);

https://docs.unity3d.com/ScriptReference/Mathf.Cla...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question