Problems with enemies in a platformer

thompsonjm22thompsonjm22 Member Posts: 15
edited February 2012 in Working with GS (Mac)
Here is my dilemma.

I want my enemies to act much like the enemies in a typical platformer, like Super Mario. For my player to be able to kill these enemies I would like for the player to either use a weapon, which I think I can implement quite easily. However, the more difficult aspect is by having the player jump on the head of the enemy, much like Super Mario. Can I implement a way for the player to die on contact with an enemy, but destroy the enemy if the player comes in contact with their "head"?

Comments

  • TwilightHunterTwilightHunter Member Posts: 146
    If the player has a game X and Y attribute, I'm pretty sure you can say this on the enemy: If collides with Player Actor, and if Self.PositionY is smaller than game.PlayerY attribute -10 (Mess around with this number) destroy this actor.
  • thompsonjm22thompsonjm22 Member Posts: 15
    I'm not sure what you mean by game X Y attribute or how that relates to the enemy actor.
  • TwilightHunterTwilightHunter Member Posts: 146
    You have to make some game attributes called PlayerX and PlayerY, I think there's a tutorial on it somewhere on here, ;)
  • thompsonjm22thompsonjm22 Member Posts: 15
    I'll mess around with that and see what I can find, do you know if I can add that and have the same enemy kill the player if the player collides with any other part of the enemy?
  • TwilightHunterTwilightHunter Member Posts: 146
    Yeah, again it would have to be a game attribute. The rule would be on the enemy actor, and probably in the "Otherwise" part of the previous rule: Otherwise, change attribute: game.PlayerDies to 1 (name it whatever you want ;] ) and then on the player, if game.PlayerDies is 1.. he dies ;D
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I think the idea @TwilightHunter was to have the enemy check the player's Y value (via a constrain attribute on the player that makes game.PlayerY=player.Y) and if enemy.Y<player.Y when they collide, then destroy the enemy.

    Another way to do this is to constrain an invisible actor ("enemy's head") and then do collision checks for the head and for the body separately. It would be a resource hog with so many actors, but that's what came to mind.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • LumpAppsLumpApps Member Posts: 2,881
    edited February 2012
    It's much easier.
    Make a game attribute named playerY. In the players actor put a constrain attribute and have self.positionY constrained to this game atribute. Make an actor (lets name it feet) and use a constrain Self.y to game.playerY minus half the actors height. Make the last actors height 2 to 4 pix, a little smaller width then the player actors and make it invisible.
    Now in the enemy do a collision rule on the feet actor. In this you put whatever it does when hit on the head.
    In the player actor you have your collision rule for when it hits the enemy and in it have what happens when you hit the enemy on the side.

    What happens now is that when the player walks into an enemies side it gets hit / killed or wathever. When you jump on an enemie the actor doesn't hit the enemy but the feet do so the enemy dies.

    Hope this makes sense. I have it in one of my prototypes and works flawless.

    Cheers,
    Ludwig.
  • thompsonjm22thompsonjm22 Member Posts: 15
    Thanks for the help ludwig, if I chose your way how would I take my feet actor and move him with the player though?
  • thompsonjm22thompsonjm22 Member Posts: 15
    Also, with ludwig's technique, I find my player starting about 50 pixels lower than it should be.
  • SAZ_1SAZ_1 Member Posts: 397
    thats because your constraining the wrong way probably! ... and to make sure the feet moves with it you need to constrain the feet X to your players X position and the feet Y to your (player Y pos - player.size.height/2)
Sign In or Register to comment.