Make sprites turn individually

0 favourites
  • 8 posts
From the Asset Store
A well commented RPG game template to learn from or use as a base for your own game!
  • Hi

    this may have been answered a thousand times but couldn't find where.

    I want the enemies to always face towards the player. what i do is to compare values so when Player's X y greater than the enemy's X it mirrors accordingly.

    It works perfectly, but every enemy on screen (with the same name) will react at the same time when one of them reacts to this condition.

    How do I make them react individually?

  • Use "for each"

    First you isolate all the enemies you want to do it for, like so:

    All enemies within 200 range of player (If that was your condition)

    For each Enemy

    <Do something>

  • Where do I add the for each? searched it on the help file but didn't get if it was used as expression or what.

  • need more info..

    are your sprites top-down view or side-view or isometric?

    how are you turning your enemy sprites? rotate? set angle? mirror?

    to get the enemies to not all act in concert I do things like add random(x) to the equation. and if they are turning or rotating toward the player, you can turn at different rates so they don't all look like copies doing the same thing..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's a CONTRA style game, a sidescrolling shooter. I'm turning then with the mirror action.

    for now it's not a problem if they act the same. I'm dealing with a more basic problem for the moment.

    It's

    SYSTEM; compare values, if player.X > enemy.X - enemy - set mirrored

    Where would the "for each" go there and how?

  • I sent you a PM with a link to an old project. I think it will accomplish what your looking for.

  • It's SYSTEM; compare values, if player.X > enemy.X - enemy - set mirrored

    Where would the "for each" go there and how?

    If you only use a System, then you are not doing any picking of specific enemies, then a For each wont help you.

    Here is some example of how it works. You have a player (Green square) and 3 enemies (Red squares) and an approx. distance of 400 between the player and the last enemy. Each Enemy also have a Variable called "Enemy_Alive" and going to use distance and that variable to change the color of valid enemies.

    So in the first example, not using a For each. I haven't specified which enemies to check the distance against, And even though 2 of them are within range they do not change color.

    Example two is the same as the first, except it uses for each, so it will check distance for each of the enemies. And 2 of them change color.

    In the last one, they are all within distance, but a condition where they also have to be alive is needed, and only the middle one is alive so it changes color.

  • Thanks TheDom for the project, gonna check it right now.

    And also to nimos100. Your explanation was quite useful and detailed. Now I've found the for each and made it work.

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