Page 1 of 2
4 Direction Attacking System
Posted:
Sat Oct 06, 2012 8:28 pm
by DrakeStoel
I'm making a game where my actor can move four directions, and can attack in each of those four directions. I have a separate animation for each of those 4 attack directions, and want to use x to attack. I want to know how I could make him attack in the direction he's facing in, then return to the direction he was facing before he attacked.
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 1:31 am
by Soullem
Are you using the animation system I showed you? If so all you have to do is create a button down event that changes stance to a new number, and then make that number change the stance string to attack. The direction part is already covered if you use this method.
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 1:45 am
by DrakeStoel
Honestly, I'm not. I thought I had it figured out, but I didn't and instead of asking 6000 questions until I got it, I decided to just use separate actors for each colour.
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 1:50 am
by skydereign
Well the normal way to do 4 directional movement (and attacking) is to have a variable that represents what direction the player is facing. Usually right=0, up=1, left=2, down=3. That way when you press attack, you can do this. There are examples on the forums of four directional movement and attacking if you need them.
- Code: Select all
switch(dir)
{
case 0:
ChangeAnimation("Event Actor", "attack_r", FORWARD);
break;
case 1:
ChangeAnimation("Event Actor", "attack_u", FORWARD);
break;
case 2:
ChangeAnimation("Event Actor", "attack_l", FORWARD);
break;
case 3:
ChangeAnimation("Event Actor", "attack_d", FORWARD);
break;
}
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 1:58 am
by Soullem
Thats okay... If you dont understand than I would prefer you to use a method that you do... Skys method will work great... And the more I think about it it gets better and better than mine...
As I said before I cant wait till you I can see this game in action!
P.S. Is it a legend of zelda game or just based off of it?
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 2:02 am
by DrakeStoel
Ok, that works, but how do I make him return to the previous animation?
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 2:05 am
by Soullem
Sky might have a better method but you can do an animation finish event. In the script for each attack just change the animation to the corresponding direction.
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 2:32 am
by DrakeStoel
Ok, I've used this code in a key up event for x to change the animation back
- Code: Select all
if (dir == 0)
{
ChangeAnimation("Event Actor", "StandRight", FORWARD);
}
else if (dir == 1)
{
ChangeAnimation("Event Actor", "StandUp", FORWARD);
}
else if (dir == 2)
{
ChangeAnimation("Event Actor", "StandLeft", FORWARD);
}
else if (dir == 3)
{
ChangeAnimation("Event Actor", "StandDown", FORWARD);
}
This works fine, but it only changes back after I release the x button. How would I make it stop almost right after you attack,no matter if your holding down the key or not?
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 2:44 am
by Soullem
Dont make a key up, but an ANIMATION FINISH event. This can create an event that starts when an animation reaches its end.. (Which is what you are looking for)
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 2:48 am
by DrakeStoel
I tried that already, but it doesn't work. He stays in the stab position until I press a direction key
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 2:56 am
by Soullem
thats rather preculiar. doesn't make much sense, how did you set the coding for this?
If you did it right I don't know why that doesn't work. Sorry but I don't know if I can help. I'll test some things and see if I can find a smooth way.
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 3:07 am
by skydereign
The animation finish event only triggers if your animation is more than one frame long. That might be the reason, or your ChangeAnimation call uses STOPPED as the state. My usual solution to this is to use the state method.
http://game-editor.com/State_MethodThat way, I can have an animation finish event for any animation (one script) that can reset the player's animation. It'd use a switch statement for the state variable that is able to tell if the player is attacking, and using direction you can reset it to the proper standing state.
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 3:22 am
by DrakeStoel
Yes, that's the problem. My animation ARE only one frame. But I'm confused on how/where I would put that switch statement into my script
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 3:26 am
by Soullem
On one of my first games I had this problem. I was cheeky and added another frame of the same image. this will make it more than one frame and the animation finish event will work. just adjust the fraame rate to make him stab longer or slower.
Perhaps not the most legit method...
Re: 4 Direction Attacking System
Posted:
Sun Oct 07, 2012 4:09 am
by DrakeStoel
That works fine, but it still stays in the stab animation until I let go. I want it to stop after the animation finishes the first time
EDIT: Also, I want him to stop moving while he's attacking