How do I randomize pathfind for each sprite in family

0 favourites
  • 4 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hello all.

    So I can't figure out how to make a sprite w/ pathfinding choose different targets to follow in a family.

    I have this setup:

    (Family)- PlayerUnits

    --->Sprite1

    (Family)- EnemyUnits

    --->Sprite2

    Afterwards I copied both Sprite1 & 2 multiple times, but when I run the game all the Enemy Sprites(Sprite2) only finds a path to the main/original Sprite1. They only move to the next copy of Sprite1 when the original is destroyed.

    I am basically trying to make AI that resembles those from games like starcraft, where the enemy units just follow the nearest target.

    Any help is much appreciated.

    Thanks

  • For nearest target add a pick nearest condition something like PlayerUnits > Sprite1 pick nearest > Set destination Sprite1. Without a condition it will just pick the lowest UID Sprite1 as it is doing at the moment, you need to specify which Sprite1 it should go to.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the help, I got it to work but now I have another issue.

    They seem to be moving(aiming) as a whole instead of individually. What I mean by this is when they chase a sprite down they all end up going to the same pixel(creating the stacked effect). This is problematic because I want them to be surround the unit thus limiting the amount of enemies that can attack a single playerunit. Although when I add the "Solid" behavior only one of the enemysprite moves to the location. I believe this is because they are all aiming for the same specific pixel.

    Is there a way I can work around this? Like have them "react" to if a spot they are trying to move to is occupied then take the next available space?

    EDIT: Basically I want to implement this type of syntax per instance of "enemysprite":

    For each UID of enemysprite; Find path to nearest playerunit

  • Yeah plus you'll want it to be nearest playerunit that isn't already being overlapped right?

    It would normally be - for each enemy sprite > find path to nearest player unit - but since you want it to do checks for if the player has been targeted...

    In its basic form, when an enemy unit overlaps a player, or 'has reached destination' in the pathfinding you could toggle a player instance boolean 'isTargeted'.

    Then when you run -for each enemy sprite > find path to nearest player unit - add a condition under for each enemy sprite that player is not targeted (isTargeted set false).

    Of course this is getting out of simple mode now as you will have enemies moving to a player as its destination before it is set to isTargeted so you will need to be either running this check every so often to find a new destination or use the 'destination failed' event on pathfinding.

    If you want a specific number of enemies to reach that destination instead of just one, you could have the isTargeted as a number and add 1 every time an enemy gets there and when it hits 6 or whatever the total is then it doesnt become a destination anymore. You'll just have to build it a bit at a time to get what you eventually want.

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