# How do I spawn multiple enemy A.I?

1 favourites
• 3 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
• I made basic enemy A.I that move towards the player and stops when it reaches the player. I made a spawner that spawns a new one every three seconds, but the issue is that they all move the same way. If one reaches me, they all stop. The all move in the same direction at the same time and I want to know how to spawn new ones with individual movements. My game is a platformer.

#### Tagged:

• How have you done the movement logic so far? You could use instance variables to define a certain direction or type of movement, and you pick the enemy at the time of creation to assign the variables. You could say on created, give variables choose(0,1) either 0 or 1, then have logic if variable =0, set angle 0 if variable=1, set angle 180, this in its basic form would allow an enemy to move left or right on creation.

By at the same time I assume you mean the speed of movement, again you can define this in a range on creation, the issue you have is probably nothing is defined and all enemies are created with same speed, you can say on created enemy set movement speed to random(300,500) for example to give it a speed within a random range.

As for stopping when it reaches the player, this should only really apply to the enemy that reaches the player if the logic is done right. For example if you had enemy overlapping player, disable movement then this would only pick the enemy that is overlapping the player.

Depending on how complex the game is, what I like to do, and I guess others, is to use instance variables as states for "walk" "attack" "stop" etc. You can define this with functions where you send the enemy's UID through the function to ensure it is that specific enemy to do the actions and then you run the relevant logic for "walk" "attack" "stop" etc

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Well the way I did it is if the player is to the left of the enemy, the enemy will move left by using the "Simulate Control" action. Same with the other way. The movement for the enemy works good, the movement speed is fine, but when I spawn in multiple on a loop using the "Create Object" event for every three seconds, they all move in the exact same way. Meaning if one makes it to me and stops, they all do, and if that one moves right to follow me the ones far on my right will move right too and walk off a cliff even. I want them to each have their own individual mind that controls them rather them all controlled by the same controller.

• 3 posts