Enemies follow MULTIPLE players

0 favourites
  • 6 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Obviously everyone here should know how to make an enemy follow the player... I currently have 4 players, each with a different instance variable "player"... however, currently this is the code I'm using:

    For Each -> Baddie : Baddie -> Rotate 3 degrees toward (Player.X, Player.Y)

    Which makes the Baddie follow Player instance variable 0... for some reason, rather than all of them. How would I make it, so that it follows the closest one for example?

    I can't even do a "distance(Baddie.X, Baddie.Y, Player.X, Player.Y" because it assumes the first player instance.

    I really don't want to quadruple up on all my events to separately track each player.

    Any pointers?

  • system pick nearest player?

  • I think I figured it out.... but this may not be the best way:

    Rotate 3 degrees towards (Player(0).X, Player(0).Y)

    only thing is, I'll have to do that four times to each reference of "Player"... sigh.

    Is there another way? At least I have it working... some what.

  • system pick nearest player?

    Never heard of that... nor do I see it... how can that be used in an action?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry I'm not at my computer right now. So I can't check what I'm saying.

    It's not an action, it's a condition to reference the right object.

    It might be a condition of the player object itself though..

    player pick nearest to baddy.x, baddy.y

    add that condition and the action will apply to that player..

  • Thanks man - it worked. Hard to get your head wrapped around the way it works sometimes... but it makes sense now. :)

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