Hit from top
redfire082
Member Posts: 3
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
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
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.
are you suggesting creating enemy & player attributes rather than scene? I took a look and cannot find a .head or .foot attrib?
Cheers,
Carl
Yes, sorry for laughing .
You have to create it.
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?
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.
Just a thought.
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.