# AI moving forward without spawnpoints?

Hi i would like to know if its possible to get the ai to move forward without using waypoints im making 2d shoot em up flying game?

transform.Translate(0,0,speed/- 20*Time.deltaTime);

put it in the enemyscript

I see you answered your own question, but I wanted to elaborate.

Yes, there are a number of ways depending on how complicated you want to make it. At the simplest level you could do:

``````function Update () {
transform.Translate(Vector3.forward);
}

``````

if you wanted something more complicated you could do something like:

``````private var movingAtAngle = false;
private var rotating = false;
private var spottedPos : Vector3;

var turnAngle = 30;
var sight = 10;
var speed = 20;

var returnToForwardPath = 5;

function Update () {
if(!rotating)
transform.Translate(Vector3.forward * speed * Time.deltaTime);
if(Physics.Raycast(transform.position, transform.forward, sight) && !movingAtAngle) {
rotating = true;
spottedPos = transform.position;
}

if(rotating) {
transform.Rotate(0, turnAngle * Time.deltaTime, 0);
if(Mathf.Abs(transform.eulerAngles.y) > turnAngle) {
rotating = false;

turnAngle =-turnAngle;
movingAtAngle = true;
}
}

if(movingAtAngle) {
if(Vector3.Distance(transform.position, spottedPos) > returnToForwardPath) {
transform.Rotate(0, turnAngle * Time.deltaTime, 0);
}
if(Mathf.Abs(transform.eulerAngles.y) < 3) {
movingAtAngle = false;
}
}
}

``````

This would have the enemy swerve to avoid the oncoming obstacle. It swerves predictably right the straightens out. It is very basic, it won't turn while not facing the global forward so it is a predictable AI pattern for shoot 'em up kind of games.