Change direction after time or position met?!?!

Hi there,

Another noob issue. I am making a 2D shooter and I want one of the enemies to change direction, either after a predetermined amount of time, or when a certain XY point is hit… either way would be fine.

This is the code I have:

var Enemy01 : Transform;
var fWait = 3;
 
function FixedUpdate()
 {
 Wait();
 }

 function Wait()
 {
 transform.Translate(0.2, -0.2, 0);
 yield WaitForSeconds(fWait);
 transform.Translate(2, 0, 0); // This SHOULD just move the character to the left?!?!
 }

It kind of works but the problem is… for some reason, he continues to move down slightly, as well as speeding up to the left. Not quite sure what’s going on.

I have probably done this a horrible way, being a noob, so any help would be muchly appreciated! And please try to keep it as simple as poss, as I’m quite dumb. LOL.

Cheers!

Translate is a movement that is relevant to the current position and will always move the object.

transform.Translate(0.2, -0.2, 0)

will be your constant movement problem. Just set Y to 0 and it should stop moving in the Y direction.