Can we kill this machine in this situation? Collusion angle important.

Hi,

I would be pleased, if you could help me. The search was unsuccessful.

The situation in the game:
Two machines shoot on top of each other. The body of the machine can turn like a tank. in x, y and z (because of the ground or terrain).

The Problem:
This Code calculates the angle (degrees) between the rotation of the transform of an object (machine) and a target (projectile):
var angle : float = Quaternion.Angle(transform.rotation, target.rotation);

But the calculated angle changes, even if the machine turns around the z-axis (on this picture blue-axis), right now in this situation it is unimportant for calculation (Of course it is from the left side or right side important but in this frontal situation, It should be ignored. If you rotate the Machine on the z-axis for 20 degres, the angle of collusion changes from 90 degrees to 110 degrees, in this test situation, if you rotate the object on blue z-axis, it should stay on 90 degrees.

alt text

The goal:
Calculate the Impact angle between airline of the projectile and the machine, dependent on the angle size calculate the damage on the machine. No matter how the machine stay in game area, it should be possible to calculate the collusion angle correctly.

And now, we can kill this machine :slight_smile:

I look forward to your answer. Thanks Guys

Muro

Quaternion.Angle always returns the shortest angle which rotates the whole quaternion to the target rotation. That means the axis around you rotate can change depending on how the quaternions are in relation to each other.

Use Vector3.Angle instead and pick your desired axis. For example transform.forward or transform.right.