How do I have mutiple's of the same object act differently

0 favourites
  • 2 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • i am fairly positive that this has been asked before but i have spent the past hour searching for it.

    so i feel stupid for asking this but

    how do you have multiples of an enemy for an example that only trigger when the event is activated independently. for example i created a simple AI for spiders to move, its just a every 1,2,3 second event

    but it seems every spider would change movement at the exact time. so if the trigger picked 3 then every spider would change movement on the 3 instead of picking 1,2,3 independently.

    i also have a simple program if the main character is within X,Y of the enemy. then have enemy move towards her.

    however it triggers every enemy on the layout even ones that are fair away. and correct me if im wrong but having clones of the same monster and long copy paste code for each one is cumbersome and eats resources i think?

    anyways thanks for looking! i look forward to the replies!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The trigger event needs some kind of reference to the object your trying to manipulate.

    In lots of cases, developers continually or periodically loop through the involved object, for each.

    for instance,

    event

    for each enemy

    compare 2 values: distance(enemy.x,enemy.y,player.x,player.y) < 100

    action

    enemy move towards player

    Here, because the for each determines one of the looped objects potentially being closer to the player then 100 pixels, then uses that object, which is automatically referenced due to the loop, and performs the desired action.

    In other cases, a reference could be an overlaps/collision

    event

    enemy is overlapping/is colliding with player

    action

    enemy do something

    Here the reference is determined by the overlapping/collision event

    without such a reference, construct 2 will interpret an action such as:

    event

    Every 3 second

    action

    enemy move left

    like you are referencing ALL enemies, as there is no reference to an instance.

    Same goes for:

    event

    on start of layout

    action

    destroy enemy

    which will destroy all enemies on the layout

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