What I am trying to do, is creating a game where the player do the normal stuff: walk, jump, attack. I want the character to extend a sword or other weapon when attacking. I have figured out how to do the walk and jump-part, but I'm struggling with adding a proper attack for it, especially when I also want the player to be able to attack both when standing on the ground as well as being in the air. I also want the character to switch to a "falling" animation when in the air (instead of just playing a walking animation when there's no ground to walk on ). To get the "falling" part I used this code (which I found here in a topic somewhere):
- Code: Select all
if(yvelocity<=-3||yvelocity>=3)
{
if(right==1) //facing right
{
ChangeAnimation("Event Actor", "FALLING right", NO_CHANGE);
}
if(right==0) //facing left
{
ChangeAnimation("Event Actor", "FALLING left", NO_CHANGE);
}
canjump=0;
}
For the walking animations, I use codes that looks like this:
- Code: Select all
char *key=GetKeyState();
if(canjump == 1)
{
if (key[KEY_LEFT]==0&&key[KEY_RIGHT]==1) ChangeAnimation("Event Actor", "WALK right", FORWARD);
else if(key[KEY_LEFT]==1&&key[KEY_RIGHT]==1) ChangeAnimation("Event Actor", "STAY right", FORWARD);\
}
right = 1;
Now I'm wondering if I've chosen the wrong way to do it since I have problems adding an attack. It seems the "falling" code is messing it up whenever the player is trying to use the attack while in the air (it doesn't work at all, or it shows the attack animation for a brief second and then switches back to the falling animation). I have no experience in creating codes, so everything I've added were from topics and demos from the forum.
Can anyone give me some suggestions on how to add an attack, or maybe another way of doing it?
Thanks for helping out a noob