Game: Attacking in Multiple Directions

[size=2]I have a “hero” movie clip on the stage. His directional movement is animated using four frames with four different movie clips inside those frames. The four movieclips are called up, down, left, right, respectively. On key press “down” the main hero movie clip will gotoAndPlay the “down” movie clip. So basically it is Hero_mc [up_mc,down_mc,left_mc,right_mc]. My question is: how can I assign attack movie clips to the spacebar but yet still have him attack in multiple directions? I want the hero to attack in the direction he is facing only using one button. So if he is facing up and the spacebar is pressed the “up attack” will be played. Likewise if he is facing right and the spacebar is pressed then the “right attack” will be played. Thank you guys for any help you can offer.

[/size]

http://baiwanfuong.notix.net/omq.htm

This is my game thus far…

What I did was everytime the hero travels right I’d make the AS set a direction (direction=“right”) So when you pressed the attack button then (gotoAndStop(direction+“attack”); so then it would go to “rightattack”.

Thanks Chen for the quick response. Great game by the way too. I am going to give your suggestion a try. It sounds like it is just what I needed. Thanks again.

Thanks and no problem. I really hope my suggestion works for you.

Chen, it worked great.

Ok, I have a new problem. I used the same basic trick as above but it is only working on one side.

onClipEvent(enterFrame) {
  	
  if (Key.isDown(Key.LEFT)) { 
  		_root.guymain.gotoAndStop("walkleft");
  		_root.guymain._x-= 5;
  		direction="left"
  }
  
  if (Key.isDown(Key.RIGHT)) {
  		_root.guymain.gotoAndStop("walkright");
  		_root.guymain._x+= 5;
  		direction="right"
  		}
  else {
  	_root.guymain.gotoAndStop(direction+"breath");
  }
  }

The left walk animation does not play at all but, when I release the left arrow key it does play the left breath animation. The right side works great. He walks right and when I release the right arrow he breaths like I want.

Dang… hmmm… i don’t see anything wrong with the script itself… have you checked the spelling and spacing on the frame label? Did you forget to name them? ( I’ve done that before…) hmmm…

Well… since pressing left does seem to change the direction… I think it must be the spelling of the frame label… if you’ve spelt it correctly on both the actionscript and in the guymain movie clip… then I’d suggest trying to rename the instance name and paste it in the AS… and then renaming it back if you want… if that doesn’t work… I don’t know…

Chen,
Everything worked out when I used “else if” statements after my first “if” statement. Weird. Anyway, one last question I have for you is that on your game if a player presses the attack (s) key it plays the attack animation even if you release the key before the animation is complete. My character starts the animation but if I release the button before the animation is finished it will only show part of the animation. Any ideas?

That’s good… I’m glad its resolved…

Anyway, one last question I have for you is that on your game if a player presses the attack (s) key it plays the attack animation even if you release the key before the animation is complete. My character starts the animation but if I release the button before the animation is finished it will only show part of the animation. Any ideas?

Make the attack action trigger a true false variable…
attacking = true

Be sure to add “_parent.attacking = false” to the end of your attack animation and to the begining of your injury animations…maybe even to the begining of your breathing animations just to be safe…

Then… add to all your conditions other than the attack condition…
if (… … … && attacking != true){

… I hope that helps…

Having a tougher time with this one. Could you please explain this in a little more detail like what exactly this code is doing? If you don’t want to do that just give me a couple of keywords to google. I GREATLY appreciate all of your help, Chen.

he’s saying that whilst the attack animation is playing, you need a variable to contain true. once the animation has stopped playing, set the variable back to false.

in doing this, it allows you to check if your hero is already attacking when the player presses a key. to do this, simply execute a basic if () { } style statement and if it returns false then we can continue to attack. hope this helps.

Essenitally all this code is preventing your character from reverting to the breath animations when you let go of the attack button…

Make it so when you press the azttack button… attacking = true

Under the breathing conditions… add “&& attacking != true”.

INSIDE the attack animation… at the very end of the attack… add this code to a frame _parent.attacking = false

This will make it so your character will follow through with the attack without interuption from breathing…

You may need to do something similar with injury animations…

I hope that helps… if you need any more help feel free to ask…

Guys,
That helps very much. Thank you.