Hit from top

Hi all,

I've been working on a game which has a specific way to destroy the enemy.

If enemy is hit from top left, the enemy dies
If player hits enemy anywhere else, player dies

Player can move any direction but enemies only move left (various heights) wrapped in 1 screen.

I found a site which gives "Mario" style kills which is the closest solution I found. This solution tracks the enemies top pixel and players bottom pixels to detect collision and this works.
Problem is, the enemy actor spawns multiple times on the same level and therefore I would need to create 20-50 iterations of the same actor and 20-50 attributes to track them (not something I want to do).

Other solutions I've found are hit boxes ... I would create 1 small hit box at the top left of the enemy and constrain the x/y ... but the tracking issue would still be there when spawning same enemy numerous times wouldn't it?

I'm not a defeatist so I refuse to compromise ;-) I'm running out of ideas so I'm hopping some brainy talent can provide some fresh alternatives ... or at least confirm that there's no way this can be done, lol.

Cheers,

Carl

Answers

  • mrpacogpmrpacogp Member Posts: 400
    I have test that and found another solution.
    Constrain top enemy to self.head.
    If self.head > player.foot change attrib game.playerdead to true
    If self.head < player.foot change attrib game.playerwin to true
    MAybe this help you
    I have used on my game and works with alot of enemys on screen.
  • redfire082redfire082 Member Posts: 3
    Thanks for that mrpacogp,

    are you suggesting creating enemy & player attributes rather than scene? I took a look and cannot find a .head or .foot attrib?

    Cheers,

    Carl
  • mrpacogpmrpacogp Member Posts: 400
    =))
    Yes, sorry for laughing .
    You have to create it.
  • gamesfuagamesfua Member Posts: 723
    This may sound nuts and may be very experimental, but what if you try something like this...
    Have an invisible actor that will serve as the hit box actor. Use this actor and constrain it to your enemy's head or whatever. Now i know this becomes hard and bad on performance when theres 20 enemies. Soooo, what if you simply keep moving the hit box to each new enemy?
    Meaning, you only have one hit box, and that hit box keeps traveling from one enemy to the next. So if lets say it was a mario game, youd have this hit box on the first enemy that comes your way. Then put a rule that if marios distance from an enemy is x amount of pixels past (i.e. has traveled behind mario), then constrain hit box to next enemy which is x amount of pixels ahead of him. I know this sounds nits and im not even sure its logical, but it might just work. It would allow you to only be constraining a few things at a time instead of 20+. Each enemy could have a rule that IF their x coordinate distance is x from mario, to then turn on a boolean (or whatever) trigger to be constrained to the hit box (or more realistically the other way around).
    Make sense?
  • gamesfuagamesfua Member Posts: 723
    Using my example above, you could also say IF mario hits enemy and boolean is true (the boolean trigger we used for the hit box to know to constrain to enemy) THEN destroy enemy and move hit box to next enemy.
  • gamesfuagamesfua Member Posts: 723
    It says this question has been answered. Which method worked, im curious
  • redfire082redfire082 Member Posts: 3
    Hi mate,

    I haven't marked it as answered ... strange ...

    anyway, really appreciate your idea (I like out-of-the-box thinking) but for my game it wouldn't be feasible I don't think. Basically there are occasions where many enemies could be clustered together and they move quite fast ... the amount of movement the hit-box would need could potentially be immense.

    A friend of mine suggested splitting the enemy in half. I think what he means is to have a hit box constantly attached to his head for all spawned instances and if it on head he dies, if hit below it player dies ... still the same situation with hit boxes though.

    After thinking about it and boiling the issue down to the simplest component what I require is:

    If player hits enemy anywhere above half y, then destroy enemy ... below half y then destroy player.

    I'm currently tracking the top of the enemy via :
    self.position.Y +(self.Size.Height / 2)

    I'm tracking bottom of player via:
    self.position.Y -(self.Size.Height /2)

    I'm struggling to see how I can accomplish this using 1 set of attribs. for the enemy actor. It's looking more and more like I need to create 50 enemy actors, lol.

    Any further suggestions would certainly be welcome.
  • gamesfuagamesfua Member Posts: 723
    edited January 2013
    Can you not have an enemy have a self attribute that assigns it a value? Thus saying if mario hits enemy, AND if enemy is value x then do y? Thereby allowing one enemy actor but having an assignment of varying numbers?
    Just a thought.
  • redfire082redfire082 Member Posts: 3
    Will try it this morning mate and update this post. The difficulty at the moment is for GS to consistently detect collisions for multiple spawns on the same actor.

    The gutting thing is that this is the last piece of the puzzle for the game :-) once I have it done, it's complete, lol.
  • gamesfuagamesfua Member Posts: 723
    Good luck! Every suggestion ive given is merely theory. Easier said than done. I hope it somehow magically give you, or points you, in the proper direction.
Sign In or Register to comment.