Left/Right, Up/Down and Distance Detection

0 favourites
  • 7 posts
From the Asset Store
75 power-up sound effects; bonus and notification sounds, fanfares, harp glissandi, stabs, clock ticks, etc.
  • Hello there, fellow makers !

    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 !

    Thank you all. You rock

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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 !

  • Use System > For each

  • 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...

    The thing I'm wondering the most about is that my two other enemies, the Jumper and the Toothmate (great names uh ? ), 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.

    By the way, I am really sorry that I get in trouble that much...

  • Sounds like you need to use the condition ...

    Sprite > Pick nearest/furthest ... x= Player.X & y = Player.Y

  • That sounds me a lot!

    Fordyce

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)