ok so i know similar questions have been asked and answered a ton of times but i am still having trouble.

i have a gun that i am using transform.LookAt to look at the player, i want to attach the gun to an enemy, the problem is i want the gun to stay relatively forward facing on the enemy (so like the gun can turn 45 degrees left/right while the enemy still holds the gun forward)

i have tried:

```
transform.LookAt(target.transform.position);
if(transform.rotation.y > .45)
{
transform.rotation.y = .45;
}else if(transform.rotation.y < -.45)
{
transform.rotation.y = -.45;
}
```

it works stationary but it’s the rotation in the world so once the enemy turns it’s all ruined

So i tried euler angles:

```
transform.LookAt(target.transform.position);
if(transform.localEulerAngles.y > 45)
{
transform.localEulerAngles.y = 45;
}
if(transform.localEulerAngles.y < 315)
{
transform.localEulerAngles.y = 315;
}
```

it works with one if statement at a time but i dont know how to apply both because looking completely straight is 360/0 degrees and i want to limit its left/right rotation at 45/315

i know the answer must be simple and im stupid but it’s been a few days now and i dont know how to solve this, thanks