How to make an actor stomp on an enemy to destroy

butterbeanbutterbean Member Posts: 4,315
edited November -1 in Working with GS (Mac)
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?

Comments

  • KamazarKamazar Member Posts: 287
    I've done something similar (well, it's similar code-wise). What I made was an enemy that crush the main player whenever the main player was under it. I can tweak the rules for you.

    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).
  • butterbeanbutterbean Member Posts: 4,315
    And also for the animation piece, I was going to have her in a sitting position, so would you put animate under "if player collides or overlaps with enemy" ?

    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!
  • KamazarKamazar Member Posts: 287
    1) Yep.

    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).
  • butterbeanbutterbean Member Posts: 4,315
    Hmmm.... tried this too but not working, do I possibly need to constrain X/Y position of the actor first to the global attribute? I'll still keep working
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    If you want to do mario style crushing you should keep track of the position of mario and his height.

    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.
  • butterbeanbutterbean Member Posts: 4,315
    In order to check for those rules in the enemy, do I need to create a global game attribute for the main actor and constrain that to the main actor's self position Y or can those rules be implemented in the enemy without any game attributes?

    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?
  • butterbeanbutterbean Member Posts: 4,315
    Here's links to the behaviors, below is an adendum of the addition that got this to work:

    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 :)
  • butterbeanbutterbean Member Posts: 4,315
    Now here's a question:

    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?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Reverse the situation.

    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.
  • butterbeanbutterbean Member Posts: 4,315
    So here's what I did:

    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.
  • butterbeanbutterbean Member Posts: 4,315
    Make game attributes that store the position of the enemy. (I made one global game attribute, game.enemyposition, and constrained both the X and Y position to that attribute within the enemy actor) I also created a global game attribute game.enemyheight that keeps track of the enemy's height

    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?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    No. Try not to use the same attribute for storing things.

    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.
  • butterbeanbutterbean Member Posts: 4,315
    Make sense :) Is there a limit to how many game attributes you can create since now I'll have to create one for each enemy that is checking their height and position?

    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.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    you don't really need one for each enemy. You just need one to reference when you are colliding with it.

    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.
  • butterbeanbutterbean Member Posts: 4,315
    So what equation would I place in the inner rule to check if the player is above the enemy?
    I still keep the global attributes for the main player too?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    the same rule as stated above. You want to check if the player's position is above the enemy. And since the position of an actor is always the center of the actor, you need to take account half the height of the player and half the height of the enemy. But this is all assuming your actors don't rotate and have square collision areas. Then you need to take into account the position of the enemy.

    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).
  • butterbeanbutterbean Member Posts: 4,315
    With the Boolean attribute, does that eliminate the need for an attribute for each enemy in checking position and height?
    By multiple enemies you mean different types, not a sequence of enemies in a row correct?
  • butterbeanbutterbean Member Posts: 4,315
    With the Boolean attribute, does that eliminate the need for an attribute for each enemy in checking position and height?
    By multiple enemies you mean different types of enemy actors, not a sequence of enemies in a row correct?
  • butterbeanbutterbean Member Posts: 4,315
    Here's a copy of the rules that I did.

    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...
Sign In or Register to comment.