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!
B
5
S
1
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,

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
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562


Return to How do I....?

Who is online

Users browsing this forum: KTML5 and 6 guests