Jump to content

Problem mesh animation with a keyboard event


Zino54220
 Share

Recommended Posts

Hi gentlemen!  :)

 

I need your help again!

 

I would like play a mesh's animation with keyboard event. (I precise that the mesh is imported from Blender...)

 

If I press my keyboard touch one time, I have this :

 

 post-6162-0-49277500-1397041054.gif

You can see that my (bad) animation is correctly played... It's cool)

 

But if I press in continue the touch, I have this : 

 

post-6162-0-16817300-1397041152.gif

You can see here that the animation is "stopped" and restart if I push off the touch (the touche is push off when the mouse cursor move on the seconde .gif)

 

So  you understand my problem! If I want translate a mesh and animate it in the same time (like to make a walk animation for example) I must repair this bug!  <_<

 

I use the window.addEventListener('keydown') and ('keyup') to manage keyboard. 

 

Here a example code :

// On push on a touch...window.addEventListener('keydown',function(event){if (event.keyCode == codeToucheAvance){     scene.beginAnimation(skeleton[0],80,100);     // Add true change nothing...}});// On push off a touch...window.addEventListener('keyup',function(event){if (event.keyCode == codeToucheAvance){     scene.stopAnimation();//This line in comment change nothing... }});

The animation begin in the keydown event because in the scene.registerBeforerender(), the animation plays only when I push off the keyboard touch...

 

Thanks you for your help!

 

Zino

Link to comment
Share on other sites

var animationStated = false;

function startAnimation() {

if (!animationStarted) {

animationStarted = true;

scene.beginAnimation(skeleton[0],80,100);

}

}

Then run the function when you press the button and when the button is up set 'animationStarted' to 'false' there.
Link to comment
Share on other sites

The solution is good in part Artem! (and don't worry, I saw the missing "r"  ;)

 

Now I would like this animation plays in continu while I press the key...

 

I add the parameter "true" in "scene.beginAnimation(skeleton[0],80,100,true)" but if the button is up, the animation continue to plays...

 

 

So I look to create a new function like yours, call "duringAnimation" for example and which reload the animation if it finished...

 

In your opinion, it's a good way or not?

 

 

Thanks your for your help!

Link to comment
Share on other sites

You're welcome. I don't know, but I think anything is good enough if it works as you want in result :)

I'm a noob to programming, so I just tried to help and give an idea of how to do it (since I used quite the same logic for my own game).

I'd love to see how your thing will turn out.

Good luck, Zino54220! :)

Link to comment
Share on other sites

So gentlement! 

 

I complete my post!

 

Thanks to Artem, the main problem (which was stay with the key pressed blocked the skeleton-animation) is resolved and to make a animation in continu (like to make a walk animation with an armature for an example...), I went in bad and complicate solution... <_<

 

And with this (very good) documentation :

 

http://doc.babylonjs.com/page.php?p=24646

 

 

I realised that I can simply make this :

// In the 'keydown' AddEventListener...if(!animationStarted){  scene.beginAnimation(skeletons[0], 45, 60,true,1.0,function(){animationStarted = false;});  animationStarted = true;}// In the 'keyup' AddEventListener...scene.stopAnimation(skeletons[0]);                                                     animationStarted = false;

And I have a little result like this :

 

post-6162-0-00579000-1397496211.gif

 

(Of course it's a test :P )

 

 

If I press the key in continu, the skeleton animation plays normaly from the beginning at the end and if I press the key many times, the skeleton animation do again from the beginning (like you can see in the middle of the gif's animation when I made many press on the key)  :) !

 

So thanks you Artem and believe in your project gentlemen!

 

Zino

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...