how to achieve a "melee" attack?

MoebiusMoebius Member Posts: 194
edited July 2012 in Working with GS (Mac)
Howdy GS developers, well i will just go straight to the point, in my platformer game iam trying to implement a melee attack which means i need my main actor to inflict damage to an enemy in a very close range which the main actor has to be facing(obviously it will not attack an enemy in it's back), i've searched in the forums however i failed to understand the discussions i read, i wish someone would be so kind to be able to explain me how this work, any possible way to implement, i am obviously not asking for a template(but it would be great if i could get one :D (for learning purposes obviously).

Thank You
lightbulb studios

Answers

  • J_PANJ_PAN Member Posts: 140
    maybe you can have a actor be constraining to the main character as a range. also, you can create attributes for which side your actor is facing so that when it is facing the enemy, it will attack
  • MoebiusMoebius Member Posts: 194
    hmm... i believe there is a way to check the distance from one actor to another
    http://forums.gamesalad.com/discussion/15632/enemy-chase-player-only-when-player-is-near , however iam still not that sure about the other
  • MoebiusMoebius Member Posts: 194
    *bump*
  • HapiappsHapiapps Member Posts: 373
    Make global attributes for the players x and y. If the attribute for the other player's x and is less than … away from yours, then attack.
  • MoebiusMoebius Member Posts: 194
    well, that wouldn't fix the problem of being able to attack while not facing the enemy
  • ironDanironDan Member Posts: 148
    Make three Global Attributes (Real) EnemyX and EnemyY and DistanceToEnemy
    Then in your Player make a (Constrain Attribute) magnitude(game.EnemyX-self.positionX,game.EnemyY-self.positionY) And then have a Rule that says when game.DistanceToEnemy is less than the distance you want to be for your player to attack to make your player attack.
  • rhinokeyrhinokey Member Posts: 158
    game attributes
    melle t/f (boolean, triggered by a attack button with a when touch pressed set to true, otehrwise false) :this basicaly tells the game you are atempting a melle, this can be set to a char animation of a punch or something. even when its not hitting an object.

    character facing right t/f (boolean rule triggered by character when self.graphic flip horizontal false, set character facing to true, otherwise true) :this tells which way your char is facing, this realy only works if you use flip horizontal to change your characters direection, which you should!

    character X constrain this to your characters x pos
    Character Y do same as above but for Y (these keep track of your characters pos

    then in your monster
    make this attribute
    distance from player Real atribute (constrain this to a magnitude self.x-game.characterx,self.y-game.characterY ) this measures the distance between your character and your monster

    then in monster a rule
    when
    distance from player < (distance you want the melle to work, from center to center)
    game.characterX < self.x (verrifys the character is to the left of the monster
    game.facing right is true (verifys the character is facing right)
    game.mele is true (verifys that the char is preforming melle)

    do
    destroy actor (or take dammage or whatever)

    and another rule
    when
    distance from player < (distance you want the melle to work, from center to center)
    game.characterX > self.x (verrifys the character is to the right of the monster
    game.facing right is false (verifys the character is facing left)
    game.mele is true (verifys that the char is preforming melle)

    do
    destroy actor (or take dammage or whatever)


    that should work fine, i think putting the magnitude in the monster allows you to have many monsters work at the same time,
    if you place it in the character you would need a seperate magnitude attribute for every monster.
  • MoebiusMoebius Member Posts: 194
    @rhinokey neat indeed! just one thing missing, it works perfectly while trying to attack from the left side I mean while the "hero" is facing right, however what if i tried to attack from the right side while it is facing left but still facing directly the "monster" , any idea, but really it was a great help! thanks a lot :D
  • rhinokeyrhinokey Member Posts: 158
    hmmm did you do both rules as i said? one should work if you are on the left and one on the right.
    basicaly the same rule, but
    the fliped graphic is different,
    and also the x position is diff use >if the character is right of the monster, and < if the character is left
    so if
    the monster pos is 200 and the characters is 300 thats character>monster which means the char is to the right, so that combined with the fliped graphic true, means the char is on the right of the monster, but is facing left, which has him facing the monster

    if the monster pos is 300 and the characters is 200 thats characte<monster which means the char is to the left, so that combined with the fliped graphic false, means the char is on the left of the monster, but is facing right, which has him facing the monster

    either of those combined with an acceptable magnitude setting should yeild a hit.

  • rhinokeyrhinokey Member Posts: 158
    @lightbulb you get this sorted?
  • MoebiusMoebius Member Posts: 194
    @rhinokey haven't got time to test it, i'll keep you up to date on it, btw thanks a lot :D
Sign In or Register to comment.