I am currently exploring the world of game development with Three.js and have a specific query regarding animating a GLTF model. Is it possible to animate the model at random intervals instead of in a continuous loop? In the game I am creating, players will take care of phrogs instead of frogs, and I want the phrogs to randomly croak as an idle animation. As the game progresses, I plan to incorporate additional random animations for movements, eating, etc. However, at the moment, I am solely focused on implementing the croaking animation.
Below is the code snippet used to load and animate the model:
const basePhrog = new GLTFLoader()
var obj
basePhrog.load('assets/models/Phrogs/base phrog/phrog.gltf', function (gltf) {
mixer = new THREE.AnimationMixer(gltf.scene)
obj = gltf.scene
var action = mixer.clipAction(gltf.animations[0])
scene.add(gltf.scene)
action.play()
})
This is the structure of my animate loop:
function animate () {
requestAnimationFrame(animate)
var delta = clock.getDelta()
if (mixer) mixer.update(delta)
renderer.render(scene, camera)
}
animate()
I would greatly appreciate any suggestions or guidance on achieving the random animation intervals. Thank you in advance for your assistance!