Sign in to follow this  
cebugdev

[dx9] Directx X Mesh animation - jump

Recommended Posts

hi all,

our game is using directx X Mesh and it contains more than one animation set;
(example are)
0 = idle
1 = walk
2 = jump
...
...

Now, I am having problem on how to implement the JUMP animation when the a key is pressed.

What i did for the walk animation is to set the animation to WALK when an arrow key is pressed and set the animation
to IDLE when no key is pressed.
just like;

[source lang="C"]
if(m_input->GetKeyPress(DIK_W)) {
m_pMainCharacter->GetMesh()->SetAnimation(WALK);
} else if (m_input->GetKeyPress(DIK_S) ) {
...
} else {
m_pMainCharacter->GetMesh()->SetAnimation(IDLE);
}
[/source]

Now my problem is on how to do the Jump animation, my problem is when i set the animation to JUMP(2) the
animation will only works if a key is pressed, but when the key is released the animation stops abruptly.

So my question is how do i do the Jump animation correctly?
If i did it similar to what i did in the walk animation the jump animation will not be displayed correctly,
Scenario; If I press space bar key press down and release immediately. then I call SetAnimation(3), animation wil only done on that frame.
Sometimes it is not visible because I key press is only interpreted on the current frame but not on the next frame.


I did a checking that if the Mesh is still in the air, then i will not RESET the animation to idle,
Now the PROBLEM is JUMP animation is repeatedly played over and over again.

How to do this propoerly?

Share this post


Link to post
Share on other sites
Hiya,


The issue you are having is in your "else" clause which sets the animation to idle, so while you press the spacebar the animation is set to JUMP(2) but upon release set to IDLE(0),



There are many, many ways to resolve this. You can set a static Boolean so when the spacebar is pressed, don't allow any other animations to run until you hit the ground (another option if you have a physics library that can handle events when an object registered with the physics library hits the ground..) then set the Boolean to false. If you don't have a physics library for this or it's just a lot for you to muck with at the moment, you can get the time of the animation track when you jump and decrement a variable until it's at zero using the same "elapsed time" variable you send in to the update for the animation controller. <-- that one is a bit messy though and I wouldn't recommend it, just it's another way.



You can also set up a callback that will fire when your animation is done and thus say all is good to play another animation. This one involves a bit more work but it also allows you to do some nifty things e.g. when your character is running , when a foot hits the ground you can play some sound associated with the material type (texture) that is under the foot to allow dynamic "movement sound" based on the environment below the characters’ foot.

For this look up D3DXKEY_CALLBACK/RegisterAnimationSet/UnregisterAnimationSet/D3DXCreateCompressedAnimationSet and the HandleCallback of the ID3DXAnimationCallbackHandler interface for information regarding this callback function in the docs.



Good luck.

Share this post


Link to post
Share on other sites
Sorry I actually have a question. How did you fit more than one animation in a single file? And what program did you use? My friend is making models for me using Blender but were not sure exactly how to get multiple animations in the same .x file.

Share this post


Link to post
Share on other sites
[quote name='Tiege' timestamp='1318203321' post='4870904']
Sorry I actually have a question. How did you fit more than one animation in a single file? And what program did you use? My friend is making models for me using Blender but were not sure exactly how to get multiple animations in the same .x file.
[/quote]

we are using Panda exporter from 3ds max,
Directx .X file can support multiple animation into 1 file.

[quote]
For this look up D3DXKEY_CALLBACK/RegisterAnimationSet/UnregisterAnimationSet/D3DXCreateCompressedAnimationSet and the HandleCallback of the ID3DXAnimationCallbackHandler interface for information regarding this callback function in the docs.
[/quote]

I think this is what i need, thanks

Share this post


Link to post
Share on other sites
[quote name='Zern' timestamp='1318165378' post='4870779']
...
There are many, many ways to resolve this. You can set a static Boolean so when the spacebar is pressed, don't allow any other animations to run until you hit the ground (another option if you have a physics library that can handle events when an object registered with the physics library hits the ground..) then set the Boolean to false. If you don't have a physics library for this or it's just a lot for you to muck with at the moment, you can get the time of the animation track when you jump and decrement a variable until it's at zero using the same "elapsed time" variable you send in to the update for the animation controller. <-- that one is a bit messy though and I wouldn't recommend it, just it's another way.
...
[/quote]

I have new problem, my jump animation sequence only has few frames, therefore we have this new problem;
if i press the spacebar i set the animation to JUMP then i will not allow any other animation until the character hit the ground, but the problem is
since the JUMP animation sequence only involves a few frame animation, it finish immediately even when the object is still airborne (Our jump height is kinda big, based on specification) therefore the animation is repeated again on air.

If we add additional frame in the animation, there might be some "timing" issue that will be encountered later,

so what would be the best approach for this?

thanks

Share this post


Link to post
Share on other sites
[quote name='cebugdev' timestamp='1318224166' post='4870974']
I have new problem, my jump animation sequence only has few frames, therefore we have this new problem;
if i press the spacebar i set the animation to JUMP then i will not allow any other animation until the character hit the ground, but the problem is
since the JUMP animation sequence only involves a few frame animation, it finish immediately even when the object is still airborne (Our jump height is kinda big, based on specification) therefore the animation is repeated again on air.

If we add additional frame in the animation, there might be some "timing" issue that will be encountered later,

so what would be the best approach for this?

thanks
[/quote]



Well, as the ground below the player can "change" dynamically e.g. if the player is jumping off a cliff .. or jumping up onto a box (for example) there is no real "magical way" (that I know of, feel free to correct me anyone) to have a "one size fits all" JUMP animation that can be slowed/quickened during the duration of the actual jump while still looking good. Because the "air time" can change so much it would look weird if you are falling off a cliff for 5 seconds and your JUMP animation is stretched out that long or 2 seconds if you're jumping up on top of a box or an edge. :P


So what I'd recommend is that you have a "FALLING" animation as well, and when you jump you blend it with the JUMP animation the moment you actually JUMP.
Now of course this method will require you to know when your player is touching the ground so you can transition into a quick "Ground_Hit" animation or just go back into an idle animation depending on your needs.

Again depending on how your engine is set up if you are using a physics library you will need to query the object (bounding box sphere character controller or a dynamic rigid body or what not) or use a reference point on the mesh and send a ray "down" to decide when the player is "back on the ground."



Happy Coding and Good luck! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this