defining an arc on a rotating object

I am trying to prevent a turret from shooting in certain arcs, and I am having some trouble with the logic behind it.

Essentially, I need to have a function that returns true anytime thisArc.eulerAngles.y < 225 && > 135. When true, the turret will not fire.

Thus, the key component is composing an if statement that takes into account the rotating ship that this gameobject/turret is parented under.

Any help would be appreciated, thank you!

public bool checkFiringArc(Quaternion thisArc) {
	if(thisArc.eulerAngles.y < 360 - arc && thisArc.eulerAngles.y > arc) {
		return true;
	else {
		return false;

Solving these kinds of problems using eulerAngles is a dangerous practice. If you are only rotating your game object around the ‘Y’ axis, then you probably will get away with it. The issue is that there are multiple eulerAngles for any physical rotation, and the values you read back don’t necessarily stay in the same. For example, put this in a script and run it:

transform.eulerAngles = Vector3(180,0,0);

The values you read back will be (0,180,180)…the same physical rotation, but represented by a different set of angles.

I’m assuming that you are trying to limit the rotation of some object to a particular arc, or limit what that game object can do to a particular arc. A better solution is limit the action to a particular delta angle of some reference rotation. That is you pick a rotation that is the midpoint of the acceptable arc, and then limit the action to some fixed amount on either side of that midpoint. If you set the game object to its midpoint in the editor, you can read the midpoint in Start(). Then you can code something like this:

public bool CanFire(Quaternion rotation) {

    if (Quaternion.Angle(rotation, midpointRotation) <= max_delta)
        return true;

    return false;

If your script is attached to a ‘turret’ gameobject that is a child of a ‘ship’ game object you can do this… if you are not, i can modify it):

public bool CanFire() {
  return (gameObject.rotation.localEulerAngles.y > 225 
           && gameObejct.rotation.localEulerAngles.y < 135);

Of course, you have to make sure you pivot is correct on this object. localEulerAngles accounts for the parent.