I have a script that instantiates enemy’s around the player. I then have a script to tell enemy’s where to go. With each enemy, their speed is faster and faster. Their script looks like this.
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
//Need variables to reprisent Enemy destination(player), Distance to object), shooting(object,direction), rotation angle(direction of trigectory(raycasting)),
private NavMeshAgent nav;
private CircleCollider2D col;
private Transform player;
private Vector2 Des;
private Rigidbody2D rb;
private float thrust = 40;
public float angle;
public Vector2 dir;
//public float angle;
//public Transform target;
void Awake() {
player = GameObject.FindWithTag("Player").transform;
}
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
Des = nav.destination;
}
// Update is called once per frame
void Update () {
if (Vector2.Distance(Des, player.position) > 2.0f)
{
Des = player.position;
nav.destination = Des;
}
dir = player.position - transform.position;
angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
}
void OnTriggerStay2D(Collider2D col) {
rb.AddForce(transform.up * thrust * Time.deltaTime, ForceMode2D.Force);
//Destroy(gameObject);
}
void OnCollisionEnter2D(Collision2D col) {
if (col.gameObject.tag == "Bullet")
{
Destroy(gameObject);
//Destroy(col.gameObject);
}
}
I have already tried isolating and testing. I made a completely different script for the proximity mines, and with every mine I instantiated, it made the enemy ships move even faster. Somehow all of their combined thrust is tied to one another. I have no idea how this is possible.