Moving Enemy Formation

I just wanted it noted for the record that I did come up with a way pf moving the enemy formation all on my lonesome :grinning: and without any help from the lecture. Of course when I watched the lecture I couldn’t believe how condensed he got the code :scream:.

Anyway, a very good learning exercise. Although I do have an excuse it was after a Jujutsu lesson in 40C heat - and I’m sticking to it :slight_smile:. The code I used was here:

void Update () {
	//this should stop movement on the left
	if (leftMovement==true) 
	{
		print("LeftMovement = " + leftMovement);
		if (transform.position.x - (width / 2) > -8) 
		{
			transform.position += Vector3.left * speed * Time.deltaTime;
		} 
		else 
		{
			print ("you can't go any further left"); 
			leftMovement = false;
			rightMovement=true;
		}
	}
	else if (rightMovement==true) 
	{
		print("RightMovement = " + rightMovement);
		if (transform.position.x + (width / 2) < 8) 
		{
			transform.position += Vector3.right * speed * Time.deltaTime;
		}
		else
		{
			print ("you can't go any further right"); 
			leftMovement = true;
			rightMovement=false;
		}
	}

//end that labourious code 

}//end function

You see perfectly straightforward :grinning: :blush: :joy:. It “did” work amazingly, although I am looking to replacing this code with the much more straightforward version.

1 Like

Privacy & Terms