Make sprites turn individually

Get help using Construct 2

Post » Wed Apr 29, 2015 11:21 pm

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?
B
5
S
1
Posts: 92
Reputation: 609

Post » Wed Apr 29, 2015 11:27 pm

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>
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Apr 29, 2015 11:32 pm

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.
B
5
S
1
Posts: 92
Reputation: 609

Post » Wed Apr 29, 2015 11:36 pm

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..
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Wed Apr 29, 2015 11:43 pm

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?
B
5
S
1
Posts: 92
Reputation: 609

Post » Thu Apr 30, 2015 7:30 am

I sent you a PM with a link to an old project. I think it will accomplish what your looking for.
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,283

Post » Thu Apr 30, 2015 11:50 am

Borghi wrote: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.

Image

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Apr 30, 2015 2:46 pm

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.

:D
B
5
S
1
Posts: 92
Reputation: 609


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 20 guests