how to achieve a "melee" attack?
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
(for learning purposes obviously).
Thank You
lightbulb studios
Thank You
lightbulb studios
Answers
http://forums.gamesalad.com/discussion/15632/enemy-chase-player-only-when-player-is-near , however iam still not that sure about the other
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.
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.
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.