Random enemy spawning with advanced A.I.?

0 favourites
  • 7 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Okay, I think I'm running into another problem here with my platformer.

    I have set up some random spawn points.

    The enemies are set to spawn once when the layout starts. There is a 100% chance that one will spawn, and the other only has a small chance of spawning.

    Here is the function I used to create the spawns:

    I'm going to try and spawn maybe 15 to 20 enemies in a single level, so I will place multiple spawn boxes each as a different sprite with different code. The example above just shows the first 2.

    Now, the problem I think I'm having is that if 2 or more of the same enemy spawn, they will share the A.I.. In other words, they are both acting as one unit.

    I need to make sure this doesn't happen because the A.I. is quite advanced. It will attack, use line of sight, etc. So, I can't have two of the same sprite/hitbox interfering with each other.

    Is there a way to set it to prevent more than one of the same unit from being spawned at the various spawn points? Otherwise, I need to find an alternative way to do this.

  • You could use an Array with the numbers to define each enemy, and when that kind spawns you remove that number from the Array.

    Are you using different Sprites for each enemy? Why don't spawn the Sprite instead of using the Family? Then you will be sure to spawn them only once.

  • Yeah, each enemy has its own sprite and separate hitbox. They are in containers so the hitbox is created with them and pinned on creation.

    I'm still new to C2, so I've never used arrays. I'd have to look into how to do that. If that's the best way to go, maybe someone could give me a little help.

    The main thing I want to make sure is that it's still random.

    So, if I spawned sprites instead of families, how would I make sure that they could be spawned at any of the 20 spawn points, but never be picked twice?

  • You could use an Array with the numbers to define each enemy, and when that kind spawns you remove that number from the Array.

    Are you using different Sprites for each enemy? Why don't spawn the Sprite instead of using the Family? Then you will be sure to spawn them only once.

    Well, I've been at it all day, and I'm still stuck.

    I tried telling it to spawn individual sprites, but I'd have to use an instance variable or something to tell it if that object has spawned. Unfortunately, C2 would not allow me to use "on created" as a variable. I set it to start at 0 and then change to 1 on created, then put as a condition to spawn it had to be at 0. All that accomplished was that it never spawned ever.

    I tried using arrays, but I still don't understand them. I have yet to find a tutorial that specifically relates to spawning items using an array. They are either basic tutorials that don't cover what I want or too complex for me to get what I need out of them for this purpose.

    I tried setting the value of x in the array to 0 in each cell, then changing it to 1 when the object was created, but I ran into the same problem as before. It would not create the enemy ever. I tried deleting the cell, but I don't know how to associate the cells with the enemy properly it seems.

    Can someone help shed some light on how to do this? All I want is a random enemy to be spawned, but never two of the same one.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It looks like you should be using Create, not Spawn, then you can randomly set your coordinates.

  • Well, I originally had it set to system > create, rather than object spawn another object. And I had some coordinate ranges typed in.

    I'm still not sure which one I will use, but either way, I need to get the issue sorted out with duplication or I'm not going to be able to do any of them.

  • Well, this has already been pushed back to page 3.

    The only solution I have come up with is to use multiple families, and in each one have a different sprite entirely (even though it's the same enemy type).

    So, it'd be like warrior1, warrior2, ninja1, ninja2, etc. Each with their own sprite.

    For example:

    family 1: warrior1

    family 2: warrior2

    Etc.

    So, it'd be more code to write, but each spawn area would only spawn from its list of enemies. So, warrior1 could only spawn from family 1. Then, there would never be a duplicate and I can still have it be completely random.

    Does that sound good guys? I was unable to come up with another way, possibly due to my lack of coding skills and inexperience with C2, but this looks to be the easiest way. What do you think?

    Of course, there are going to be maybe 10 to 20 spawn points per level, so I don't know how well this is going to work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)