I been working on a small tower defense style game and want to eventually have 100+ enemies moving about on my map at any given time and was wondering what the easiest way to manage their movement without dragging the game to a crawl.
so far I have tried rigid body, character controller and straight up translate:
Rigidbody method:
// code fragment dealing with enemy movment toward a target
direction = mainTarget.transform.position - myTrans.position;
targetRotation = Quaternion.LookRotation(direction, Vector3.up);
myTrans.rotation = targetRotation;
myTrans.rigidbody.velocity = direction.normalized * speed;
CharacterController:
direction = mainTarget.transform.position - myTrans.position;
targetRotation = Quaternion.LookRotation(direction, Vector3.up);
myTrans.rotation = targetRotation;
myController.SimpleMove(direction.normalized * speed );
These both work OK… probably since they are so similar, but the tend to lag up the system around 100 enemies in. With translate, my turrets fail to detect the enemies. Is there an easier way to move enemies around without using physics or an easier method for finding a direction / moving that has less impact on frame rate?
The character controller route lags a bit more then the rigid body route, but it also looks better since the enemies aren’t influenced by gravity (my rigid body enemies sometimes lay down on the job).