Left/Right, Up/Down and Distance Detection

Get help using Construct 2

Post » Sun Aug 14, 2016 2:17 pm

Hello there, fellow makers ! 8-)

I am currently working on an enemy whose actions would be something like these :
- By default, stays on the ground without doing anything. "Platform" behaviour, though it isn't controlled by the player (I disabled "default controls").
- If the enemy is currently on-screen and that the player gets close enough (which I don't know how to do), the enemy jumps then, right before it falls down, shoots a bullet-like projectile, not directly towards the player because it is not a boss, but on a 135 ° or 270 ° degrees angle depending on if the player is higher or lower than the enemy. It's on purpose that this method is quite unprecise, because it must stay an easy enemy. But that's not all. I would also like the enemy to mirror itself and all its actions (which I know how to do) whenever it detects the player gets at its right (for example, if the player attempts to skip the enemy), so it continues to try to bother the player instead of just shooting on the side the player already left.

So here it is. There are three things I don't know how to do. First, detect when the player is close enough from the enemy. I kinda remember an action that would work for this purpose, but I'm not sure. Let's say when the player is closer than 250 pixels or something like that (my enemy sprite is 32x32 sized). The things that's important with that is that you must NOT imagine a circle of detection around the enemy, but rather a rectangle, that would cover the whole vertical stage but not horizontal. Otherwise said, I want the enemy to attempt to shoot whether the player is high or low (even if I need to detect this as well), because if it kind of a circle of detection around the enemy, it won't detect the player they are too high (which is bothering me 'cause the character is able to make Super-Jumps that start with 1000 pixels jump strenght instead of 650). And finally, I would like to detect if the player is on the right or on the left of the enemy. I may have an idea for this, like test if the player's X (if that indeed is the horizontal order) is greater or lesser than the enemy's, alongside with Y for up or down.

To make this short :
- I would like the enemy to detect if the player is close enough before attacking
- I would like the enemy to mirror its actions if the player gets on its right
- And I'd also like the enemy to shoot up if the player is higher than it and down if the player is lower.

Hope someone nice will be able to give me an answer, I'm kinda stuck with this ! :cry:

Thank you all. You rock :D
B
8
Posts: 11
Reputation: 328

Post » Sun Aug 14, 2016 3:21 pm

To detect range that way, I would compare the enemy's X and Y to the player's X and Y directly, rather than using distance. For example, this would detect any enemy within 16 horizontal and 64 vertical pixels from the player:
If Enemy.X is between Player.X-16 and Player.X+16
If Enemy.Y is between Player.X-64 and Player.Y+64

To detect orientation (mirroring) simply compare the X position, like so:
If Enemy.X > Player.X set Enemy mirrored
If Enemy.X < Player.X set Enemy not mirrored

And similarly to detect if the enemy should shoot up, only by comparing Y positions:
If Enemy.Y > Player.Y then shoot up
If Enemy.Y < Player.Y then shoot down
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 245
Reputation: 2,314

Post » Sun Aug 14, 2016 4:37 pm

Thanks a lot, seems to work well ! But I actually have another problem... when I put two instances of this enemy in the same room, only one of them works, even if I used only instance variables. I don't understand !
B
8
Posts: 11
Reputation: 328

Post » Sun Aug 14, 2016 8:33 pm

Use System > For each
:)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 245
Reputation: 2,314

Post » Sun Aug 14, 2016 10:03 pm

Again, thank you, but - hey I'm sorry for this - I'm still in trouble... simply because, I don't actually really get how For each works. :|

Actually... :roll:

The thing I'm wondering the most about is that my two other enemies, the Jumper and the Toothmate (great names uh ? :mrgreen:), do not got me with such a problem. To get their behaviour fast, once Jumper has been discovered on screen it simply jumps on regular times, and the Toothmate simply walks left then after a short amount of time walks right and repeats the process.

When I say I didn't have such trouble, I mean by that that, as it should be the case for the Crasher, the enemy that's getting me crazy, each instance of 'em acts individually. For example, the Jumper. It also uses Instance Variables that are mostly made to make the waiting time between its jumps regular. And that works ! They do not all jump strictly at the same time, because this actually depends on the time they first appeared on-screen (they do not move until they're seen by the player).

However, the Crasher gets me into trouble. What I would like to happen :
- The actions that are triggered by the player being closed to a crasher should ONLY be triggered on the Crasher the player's close to. Furthermore, it should act separately from the others - which isn't the case, strangely.

What happens :
- Only the instance that I put first in the layout, i.e Crasher #0 in Debug Mode, works well. The others seem to be nothing but kind of decoys. They do not move, except that they jump at the same time at the working one and sometimes also shoot (this is not random, but it seems they shoot only one Crash Bomb before completely stopping). They do harm me with contact damage as the working one, and their Health Instance Variable do lower when I attack them, indeed destroying them when their health reaches 0, but they do not shoot, only does the #0. If you can explain me more precisely how I should use "For Each", I would be SO thankful of you. :cry:

By the way, I am really sorry that I get in trouble that much...
B
8
Posts: 11
Reputation: 328

Post » Mon Aug 15, 2016 5:39 pm

Sounds like you need to use the condition ...
Sprite > Pick nearest/furthest ... x= Player.X & y = Player.Y
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Nov 18, 2016 4:42 am

That sounds me a lot!
Fordyce
B
2
Posts: 2
Reputation: 154


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 26 guests