An object (drone turret) works just fine on it’s own, but any subsequent ones I add to the scene act strange.
With one, the drone fires correctly, with two or more drones, they all fire in the same direction as the initial one added to the scene. It’s almost as if every drone’s gun is the same instance… the rotation is based on a pretty simple look at 2d which works for the one drone
public class Drone : BaseEnemy, IHasSpecialTriggers{
Transform Gun_t;
...
Start(){
Gun_t = transform.Find("Gun");
...
}
protected void LookAt2D(Transform gun, Vector2 target) {
Vector2 current = gun.position;
var direction = target - current;
var angle = Mathf.Atan2(direction.y, direction.x)*Mathf.Rad2Deg;
gun.rotation = Quaternion.AngleAxis(angle_2, Vector3.forward);
}
}
If I make the var angle to be manually set from the inspector I can see that whatever I set the main drone gets set to, all other drones fire at that angle, but if I set the angle in the secondary drones there is no effect.
What am I missing? Where else can I look?
This object is a prefab and based on another class that has no gun.
The object Heirarchy is:
Drone
>AggroTrigger
>Gun
>>Gun_sprite (for xy offset from center of rotation)