I’m making a shooter much in the style of Doom, which means that looking up and down is disabled. I want to make it so that if you shoot in the direction of an enemy who is above you, it adjusts your raycast upwards. What can I use to tell if the player is facing an enemy? I’ve tried using vector3.angle and Vector3.dot, and I cant get anything to disregard the x rotation. Any ideas?
Project your vector on the XZ plane before doing your Angle() or Dot() calculation;
var v = enemy.position - transform.position;
v.y = 0.0;
var angle = Vector3.Angle(v, transform.forward);
if (angle < someAngle) {
Debug.Log("I'm facing the enemy");
}
And if you are using Vector3.Dot(), you’ll want to normalize the vector after projecting it.