How to make an actor stomp on an enemy to destroy
butterbean
Member Posts: 4,315
Has anyone created a platformer yet with a rule on how to stomp on any given enemy and destroy that enemy like Mario Bros. Style?
If so, has anyone also created a "stomping" animation to go with that rule?
If so, has anyone also created a "stomping" animation to go with that rule?
Comments
If player position Y is greater than enemy position Y + enemy-height/2
If player collides or overlaps with enemy
Destroy enemy and spawn crushed enemy (then handle it however you want).
If player position Y is greater than enemy position Y + enemy-height/2 ------> (Also, I couldn't find how to put in enemy position y + enemy height/2 in the expression editor)
Thanks Kamazar!
2) Eh, it depends on what actor you're gonna use to enforce the rule set. Ok, here's what I'd do. Create a real attribute for the location of the main player. When the location of the player is greater than the enemy's position (self.position.Y) + enemy-height/2 (this is simple, find out how high your enemy is, divide it by two, and enter in the expression editor).
In the enemy actor you check if:
1) Mario is colliding with the enemy.
2) Mario Y position is ≥ enemy's(self) position + enemy's(self) height/2 + mario's height/2
Then when both of those are true, Crushing can commence.
If I'm checking Mario's position against the enemies, I thought that could only be done via a global game attribute
Also, should I create another global game attribute and constrain that to the main actor's self position X?
Created 2 global game attriibutes (both Real), one called MainPlayerHeight and the other called MainPlayerposition and here's 2 links below showing the rules I created.
The first link below shows the rule under the enemy actor: if Game.mainplayerposition is > or = to self.position Y + Self.size.height/2+ Game.mainplayerheight/2
http://img232.imageshack.us/img232/6858/picture1nzs.png
Then below is a link showing the 2 attributes and what they are constrained to. game.mainplayerheight is constrained to the main player's self.height and game.mainplayerposition is constrained to self.position Y
So far this hasn't worked..... The actor doesn't destroy the bunny
http://img27.imageshack.us/img27/2554/picture3gvf.png
UPDATE:
Fixed it, works now.
What I added to the main actor was to constrain game.mainplayerposition to self position X as well as position Y
This could be added to the Wiki
I have a rule within the main actor if she runs into the enemy, she's destroyed, how do I prevent her from getting destroyed if she stomps on the enemy and only gets destroyed if she runs into him from either side?
Make game attributes that store the position of the enemy.
When the enemy sees that it is colliding with the player, change the game attribute to the enemy's position.
Then the player checks if its position is greater than or equal to the enemy position + enemy height/2 + player height/2.
Created 2 game attributes (real), one that stores the position of the enemy, and the other that stores the height of the enemy.
Here's a link to those rules: http://img140.imageshack.us/img140/8757/picture1nye.png
Here's a link to the rules that the main player checks for:
http://img149.imageshack.us/img149/8058/picture2ntl.png
What happens is that the main actor dies when she stomps on the enemy actor and when she runs into him, the stomping rule doesn't work....
**I also added to the enemy actor: When enemy overlaps or collides with player:
Change attribute: game.enemyposition to self.position X
Change attribute: Game.enemyposition to self.position Y
**Now the player and enemy both die when she collides with enemy on either side, as well as when she stomps on him.
When the enemy sees that it is colliding with the player, change the game attribute to the enemy's position. (This can be taken out if I did the above right?)
Then the player checks if its position is greater than or equal to the enemy position + enemy height/2 + player height/2. ----> If I only want the main actor to be destroyed when she runs into the enemy, and is still alive when stomping on him, shouldn't this be :
Rule within main actor: If main actor game.selfposition is < or = game.enemyposition +game.enemyheight/2 + self.height/2 (this would only destroy her when she runs into enemy and not stomping on him)
Also, can I utilize the global game attribute for the enemy for multiple enemies or can you only assign one to one type of enemy actor?
Look at it this way. You are taking a blind taste test of Coke or Pepsi and you only have one cup(your game attribute) to add liquid to it and drink from it. If you pour Coke into it and then the Pepsi, you won't get an accurate taste test.
Also, can you please look at the rules above and tell me if that should fix the stomping rule, so far I haven't gotten it to work.
If you think you will be stomping on multiple enemies at once, you could do this.
Make a boolean game attribute called IHitYou and set it to false.
In your enemy, when it sees that it collides with the player (Outer Rule), check with an inner rule that sees the position of the player relative to the enemy. If the player is above it during the collision, the enemy gets squashed, if the player is not above it(Otherwise in the inner rule), then the player gets hit and sets IHitYou to true. The player sees that attribute is true and does its thing.
I still keep the global attributes for the main player too?
In the player prototype you need to keep track of the Y position of the actor and the height of the actor. Keep these in separate, real type, game attributes so all actors can see it. Use a Constrain Behavior for each of these.
So in the enemy's point of view (inside the enemy actor prototype) you need to check if it collides with the player actor. Then check if the game attribute containing the Y position of the player actor is greater or equal to the enemy's position plus half it's height plus half the actor's height(which is stored in the game attribute mentioned above).
By multiple enemies you mean different types, not a sequence of enemies in a row correct?
By multiple enemies you mean different types of enemy actors, not a sequence of enemies in a row correct?
I created 2 Real game attributes: Game.MainPlayerHeight, constrained in the main actor to it's height and Game.MainPlayer position, constrained in the main actor to it's self.position Y
I created a boolean attribute like you said called Game.IHitYou and set it to false (unchecked)
http://img140.imageshack.us/img140/8894/picture3akk.png (here are the main player's rules)
Here are the enemy actor's rules:
http://img529.imageshack.us/img529/3659/picture1rhu.png
What happens is the main actor gets destroyed by the enemy, if she's running into him or stomping on him....
Let me know what rules I have blundered on...