Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411613 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 12:42:21 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)How to match up jumping physics with its animation?
Pages: [1]
Print
Author Topic: How to match up jumping physics with its animation?  (Read 1416 times)
iGniSz
Level 0
*


View Profile
« on: November 19, 2009, 01:47:43 PM »

Hello TIGSource,

I am currently working on a 2d platformer game and have run into a kind of problem. Since I got a lot of usefull info by lurking in these forums, I thought why not come out and ask a question?! I already introduced myself in the "introduce yourself" thread.. On to my question:

When a character in a 2d platform game jumps there is usually some kind of animation, my question is how does this animation get matched up to the actual jump?

Say I have a 7 frame jumping animation, 3 start frames, an "apex" frame and 3 landing frames. My question is: how can you elegantly map these 7 frames to the jump trajectory? Currently I am using a magic system that seems to do the trick but it is not so nice under close examination.. What do other people use? Some kind of prediction and dynamic animation schedule??

Would love some other peoples thoughts on this,
Jillis
« Last Edit: November 19, 2009, 01:52:43 PM by iGniSz » Logged
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #1 on: November 19, 2009, 02:00:47 PM »

How are you doing the jumping? Are you setting the velocity or the maximum height, and is the jump always a fixed height/time/length. Cos these things can have an effect on the overall sprite. What I'd suggest, if you have a fixed time jump, is to have a animation which plays over the whole jump. Alternatively, try and change your animation so that you have one for going up and one for coming down, then you can simply play one depending on your characters velocity.

However like I said, it all depends on your setup. Post some more info and I'm sure someone else will be able to help you more than I have...
Logged
powly
Level 4
****



View Profile WWW
« Reply #2 on: November 19, 2009, 02:08:16 PM »

Personally I like low-fi graphics so usually I just have a single jump frame that's displayed when the player is in the air.

If I had more it would probably have two animations and two long-lasting frames; the jumping animation, a going up -frame, a going down -frame and the landing animation. The timing of the jump animation is quite easy; run it when the player presses the jump key (you'll have to check which frame is the moment of actually getting off ground and do your acceleration when it's playing), then while your y-velocity is positive, show the going up frame, when it's negative, show the going down frame (if you want a super-fancy jump you can play some sort of animation at the top of the jump when y-velocity is just about 0)

The landing is a bit more complicated and depends on your animation: if the character starts to somehow prepare for the landing in mid-air, you'll have to constantly check if he's going to land anytime soon (as many frames as your animation is going to have him in the air) If it's just the character absorbing the hit when he lands, you can just play it after the contact.
Logged
iGniSz
Level 0
*


View Profile
« Reply #3 on: November 19, 2009, 03:48:00 PM »

Wow .. 2 great answers in such a short time! Hehe .. well after reading your answers and slapping my forehead a bit I think my problems have more to do with me first making the animations (a lot of work for me!) and not thinking it through right.. Ah well, this is how you learn!!

I really would like the character to anticipate landing, but not really by checking how far of the ground you are all the time. In my head this was possible :D

Well I will just have to do some more animating then and rethink the strips a bit! Right now i'm leaning to the take-off, apex, absorbtion sequence. But i'm also really tired so well see if I still feel the same way tomorrow when i'm awake again Smiley

Thank you very much dear sirs! You have made it possible for me to finally go to sleep! And actually rest a bit Smiley
« Last Edit: November 19, 2009, 03:51:57 PM by iGniSz » Logged
David Pittman
Level 2
**


MAEK GAEM


View Profile WWW
« Reply #4 on: November 20, 2009, 09:51:22 AM »

You could also make certain velocity ranges map to certain animation frames, so the animation will automatically match the jump arc whenever you tweak the jump velocity. And it will advance to the downward part if you collide with an overhead obstruction and start falling before the jump apex.
Logged

mewse
Level 6
*



View Profile WWW
« Reply #5 on: November 20, 2009, 02:49:40 PM »

You could also make certain velocity ranges map to certain animation frames, so the animation will automatically match the jump arc whenever you tweak the jump velocity. And it will advance to the downward part if you collide with an overhead obstruction and start falling before the jump apex.

This is what I typically do.  When the jump starts, you record the initial vertical velocity upward.  While the player is moving upward, you do something like this:

animationFraction = (1.0 - (currentUpVelocity / initialUpVelocity)) * 0.5;

That gives you a value in the range [0 .. 0.5], for how far you should be through your animation, as your currentUpVelocity goes from "initialUpVelocity" to 0.

Once the player starts moving downward again, you have two options.  Usually, you want to keep using the same general idea;  as the up velocity reaches -initialUpVelocity, you reach the end of the animation, and hold there until the player hits the ground.

An alternate approach I've used on a few projects is to test how high the player is above the ground each frame while he's descending, and do some maths to figure out how long it would take for him to hit the ground, and update the animation fast enough so that it'll reach the end of the animation at the same time he hits the ground.  That's often useful if you want your character to do a mid-air flip and just barely land on his feet as he touches the ground, even if he's been jumping off a cliff.  Of course, it can lead to some weird animation discontinuities if the player moves over the edge of a cliff while descending (last frame he was 1000m from the ground and this frame he's only 5m from the ground.. or vice versa), so you have to be able to cope with those.
Logged
JLJac
Level 10
*****



View Profile
« Reply #6 on: November 22, 2009, 10:13:28 AM »

That's a good way if you want the character to do a flip. If it's a standard jump I use a much simpler solution. I make three animation loops(might be just one frame for each) called "jumping", "floating", and "falling", and then I simply check the y-value of the character's speed vector.

if (yVec < - 5){
anim = "jumping"
}else if (yVec > 5) {
anim = "falling"
}else{
anim = "floating"
}

Easy as pie. 5 is just an example number, you'll have to tweak it to fit the scale of your game. Of course this could also be done with say 5 different animations for different speeds of fall/jump, or just 2 skipping the floating one.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic