[SOLVED] Assistance please with playing animation backwards

I cant seem to make this work.

I get the animation and its duration ok. Set the currentTime to the duration, set the speed to the negative, but the same (opening) animation plays (instead of closing).

Is the animation itself malformed? [exported from blender]

the relevant code:
(button toggles between open and close);

clicktest.prototype.onSelect = function (e) {
    var from = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.nearClip);
    var to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);

    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    if (result) {
         console.log(result.entity.name);
        if (result.entity.name=='btn1') {
            if (!this.open) {
            var anim = this.shape.animation.getAnimation('icosUNFOLD3.json');
               console.log(anim);

            anim.currentTime = 0;
            anim.speed = -0.5;
                // anim.play(); //*doesnt work
            this.shape.animation.play('icosUNFOLD3.json');
                this.open=true;
            } else {
            var anim = this.shape.animation.getAnimation('icosUNFOLD3.json');
               console.log(anim);
            var dur = anim.duration;
                console.log(dur);
            anim.currentTime = dur;
            anim.speed = -anim.speed;
                console.log('speed = '+anim.speed);
            this.shape.animation.play('icosUNFOLD3.json');
                this.open=false;
                
            }
        }

    }
};

the full project is at https://playcanvas.com/editor/scene/565582

thanks

k this looks like badly formed animation… watch this space

1 Like

confirming, the problem was with the animation. Exporting FBX anims from blender is complex and opaque… in the end i had to export all 15 tetrahedrons separately… but the pc animation controls as (more or less) coded above, work fine!