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

Get help using Construct 2

Post » Thu Sep 03, 2015 12:20 pm

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!
Posts: 88
Reputation: 653

Post » Thu Sep 03, 2015 12:42 pm

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,

for each enemy
compare 2 values: distance(enemy.x,enemy.y,player.x,player.y) < 100
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

enemy is overlapping/is colliding with player
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:

Every 3 second
enemy move left

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

Same goes for:

on start of layout
destroy enemy

which will destroy all enemies on the layout
Who dares wins
Posts: 1,880
Reputation: 19,623

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests