Is it possible to disable the looping of the animation when pressing a key?

Hello!
Is it possible to disable the looping of the animation when pressing a key?

:point_down:In the playground below, press “s” to make the character sit and “a” to make him walk.
https://www.babylonjs-playground.com/#G21WWU

I want the sit animation to play without looping when the “s” is pressed. Can I do this?

This playground was created based on the playground in this official document
Thank you!

Hi gt_aws,

The most straightforward way to do this might be to just track the state.

anim | Babylon.js Playground (babylonjs-playground.com)

The lines I added were 25, 26, 34, 37, 38, and 42. Pretty much all I did (aside from setting the sitting to not loop at the start) was to add a Boolean that tracks whether we’re already sitting or not and, if we are, doesn’t try to start sitting again. This is the sort of thing that will probably be handled by a formal state machine eventually; but for now, and for simple cases like these, it’s probably easiest to just track this state manually. Hope this helps, and best of luck!

2 Likes

Thank you, very much!