Enemy Formation doesn't move anymore

After adding the animation idle state my enemy formation doesn’t move according to the EnemySpawner script anymore. The enemies just animate in and stay in the end position of the animation - no left-right movement.

void Update ()
	{
		// movement
		if (movingRight) {
			transform.position += Vector3.right * speed * Time.deltaTime;
		} else {
			transform.position += Vector3.left * speed * Time.deltaTime;
		}
		float rightEdgeOfFormation = transform.position.x + (0.5f * width);
		float leftEdgeOfFormation = transform.position.x - (0.5f * width);
		if (leftEdgeOfFormation < xmin) {
			movingRight = true;
		}
		if (rightEdgeOfFormation > xmax) {
			movingRight = false;
		}
		if (AllMembersDead()) {
			SpawnUntilFull();}
	}

Hello Daniel,

The forum will support a file size of 10mb, so if you file is larger than that you will need to use DropBox or Google Drive etc. If you zip up your project files and share a link to them as a download please, I will happily take a look for you.


See also;

I was having the same issue, and then solved it nearly immediately after posting here. I had somehow applied animations to the enemy formation game object. Once I removed that component, everything worked just fine.

Sorry for the trouble!

Hello Nick,

Happy to help :slight_smile:

  • open your Game scene
  • select your Enemy Formation GameObject
  • note the Animator component
  • remove it
  • run the game

You have added this component to the Enemy Formation, and in it’s Idle animation state it sets the transforms position to zero, thus, it doesn’t move.

Whilst the game is running, click the pause button and now select one of the enemies within a Position GameObject, you’ll notice that they all have their own individual Animator components.

Hope this helps :slight_smile:

1 Like

Very helpful, and thank you so much for the quick response! The solution works great. I’m not sure how I ended up applying the animation to the Enemy Formation, but it may have something to do with accidentally deleting an enemy GameObject and then having to drag it to appropriate places in the inspector. I’ll need to be more careful with that in the future.

Thanks again!

1 Like

You’re more than welcome Nick - glad you can move forward again :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms