Enemy movement

Get help using Construct 2

Post » Mon Dec 05, 2011 10:05 pm

What's the best way to make every single instance of a sprite do an action when the main character is near that sprite?


Simply having:
Character x < Enemy.x + 100
Character x > Enemy.x - 100
----------------set Enemy X to Enemy.x + 1

would make every instance of Enemy move if the Character is 100 pixels in front or behind of the first Enemy added to the layout.
It doesn't check the conditions for every instance of Enemy individually.
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Mon Dec 05, 2011 10:26 pm

Invert your logic.

Instead of comparing character.X, compare Enemy.X

Enemy.X >= Character.X - 100
Enemy.X <= Character.X + 100
=> enemy.Move forward 1 PX

The enemy will go to the right (if its angle is 0) if the character gets anywhere the 100 pixels range area around it.

And it applies to all instances of enemy.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Mon Dec 05, 2011 10:52 pm

A new question appears: why didn't I try this before?

Thanks.
B
33
S
12
G
7
Posts: 227
Reputation: 7,582


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, Magistross, PavleNikolic and 22 guests