Page 1 of 1

Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 5:31 am
by arcreamer
Hey so I'm trying to figure out how to make it so that my character does a certain animation when I press the jump key, but once he reaches his max height of elevation and begins to fall, he switches to a different animation. Is there a way to do that?

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 5:34 am
by skydereign
I'd suggest using the state method. http://game-editor.com/State_Method
That way you can easily write code that can target individual actions the player does (like jumping). But, if you know the animindex values of jumping, you can use it in the same way. Essentially, an if statement checking if the animindex corresponds to a jump animation, and checking if yvelocity>0 (falling) change the animation to your fall animation. That way the if will make sure you only change the animation when the player is jumping, and begins to fall.

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:13 am
by arcreamer
Trying to understand what you linked, but I'm not gettin it. lol. I tried the if yvelocity = 0; it would switch the animation, but I already had a draw actor script with yevolicty=yvelocity+1; for gravity, so it didnt work. wouldnt let me jump

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:18 am
by skydereign
Not yvelocity=0, that would set yvelocity equal to 0. You can use inequalities in if statements, so you can check if yvelocity is positive. You know that if the actor is jumping, and they have a positive yvelocity, that means they are falling.
Code: Select all
if(animindex==4 && yvelocity>0) // assuming 4 is the jump animation

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:24 am
by arcreamer
well I plugged in what you wrote, along with the change animation thing, but now it just looks like my character is havin a seizure.. and doesnt change the animation at all when I jump

Code: Select all
if(animindex==4 && yvelocity>0);

{
    ChangeAnimation("Event Actor", "Standby_1", FORWARD);
}

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:27 am
by skydereign
That's because you are using if incorrectly. You are ending the if prematurely, so that code with the {} always runs. Remove the semicolon after the if, and it won't do that.

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:29 am
by arcreamer
Gotcha. Alright so I removed the semicolon, now its seems to have fixed the seizure problem, but hes not changing his animation when hes falling

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:33 am
by skydereign
Well, as the comment in the code I posted says, that would only work if animindex 4 is your jump animation. You can tell the animindex values for animations by looking at the order they appear when you go to change animation (starting with 0). So if you still can't get it after this post, type up the list of animations your actor has in the same order as gE shows you.

Re: Changing animation mid-jump

PostPosted: Mon Jan 07, 2013 6:34 am
by arcreamer
Ooh, I had it as my 4th, didnt know it started with 0. Its working now, thanks man