Help with Weapon Movement Script

Talk about making games.

Help with Weapon Movement Script

Postby tnguy22 » Fri Sep 30, 2011 12:32 pm

i'm a true beginner to GE but i've learned some scripting methods for moving a character around this board. So thanks for all of that!

The issue i have now is just testing a blade/hit animation. when the player is facing right and i hit the "a" key i want the sword hit animation to happen. so far it does work but it never comes out of the frame and go back to the standing right position.

here is the code im using for this. Any help would be greatly appreciated

char *key = GetKeyState();

if(animindex == getAnimIndex("StandRight"))
{
if (key[KEY_a]==1)
{
ChangeAnimation("Event Actor", "SwordRight", NO_CHANGE);
}
else if(key[KEY_a]==0)
{
ChangeAnimation("Event Actor", "StandRight", NO_CHANGE);
}
}
tnguy22
 
Posts: 5
Joined: Fri Sep 30, 2011 10:45 am
Score: 0 Give a positive score

Re: Help with Weapon Movement Script

Postby skydereign » Fri Sep 30, 2011 11:48 pm

By any chance do you have a collision script that changes the actor to stand? It sounds like the problem is that the animation is being reset, and that else if you have there in the code will never trigger if you are attacking. Notice it is in an if, that checks if the animation is the StandRight animation. So, if it isn't, it will never run the else if that resets your animation to StandRight. Am I right to assume you put this in the draw actor event?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Help with Weapon Movement Script

Postby tnguy22 » Mon Oct 03, 2011 10:28 am

at the moment i have no Collision written. im just wanting to get all of the movements coded first then move on to the more detailed part of the game. which i'm sure i'll need help with as well lol

thanks for the reply
tnguy22
 
Posts: 5
Joined: Fri Sep 30, 2011 10:45 am
Score: 0 Give a positive score

Re: Help with Weapon Movement Script

Postby foleyjo » Mon Oct 03, 2011 11:16 am

Heres how I would do it

Code: Select all
char *key = GetKeyState();

if (key[KEY_a] && animindex == getAnimIndex("StandRight"))
   ChangeAnimation("Event Actor", "SwordRight", NO_CHANGE);

if (!key[KEY_a] && animindex != getAnimIndex("StandRight")) 
   ChangeAnimation("Event Actor", "StandRight", NO_CHANGE);


However thinking ahead this would cause problems unless the player can only hit from facing right while standing still.
If the player can also swing the sword while walking then it would have to be

Code: Select all
char *key = GetKeyState();

if (key[KEY_a] && animindex != getAnimIndex("SwordRight"))
   ChangeAnimation("Event Actor", "SwordRight", NO_CHANGE);

if (!key[KEY_a] && animindex != getAnimIndex("StandRight")) 
   ChangeAnimation("Event Actor", "StandRight", NO_CHANGE);
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Help with Weapon Movement Script

Postby tnguy22 » Mon Oct 03, 2011 8:58 pm

thanks foleyjo,
the code didnt work 100% properly as it basically killed all of my other movement functions. but i toyed with it and got it working properly

thanks for the help and i'll give you +2 for the code bc it helped me further along my game :)

Cheers!
tnguy22
 
Posts: 5
Joined: Fri Sep 30, 2011 10:45 am
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron