Stop animation on first frame


#1

Hi,

I have a game object that plays an animation when the player touches it.

I would like this object to be idle: don’t play the animation until it is asked to.

My issue here is that if I enable the activate checkbox in the editor, the animation plays automatically when the scene is loaded.

If I disable the checkbox, the model does not even show up until I call animation.play("name").

How can I have my model be displayed on the scene, and the animation stopped on the first frame until I call play?

I have tried a few things and managed to make it “work”, but this is veryyyy ugly:

var emptyfunction = function() {};

Bumper.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onTriggerEnter, this);
    this.model = this.entity.findByName("Model");
};

Bumper.prototype.onTriggerEnter = function(e) {
    // now that I call animation.play(), I can remove the update function that stops on first frame
    this.update = emptyfunction;
    this.model.animation.play("anim.json");
};

// force the object to be stopped on the first frame
Bumper.prototype.update = function(dt) {
    this.model.animation.currentTime = 0;
};

Is there a more efficient/proper way to do it?


#2

up


#3

Post a simple example project showing the issue, that might encourage someone to fork it and try to fix it


#4

I created a sample project here: https://playcanvas.com/project/642733/overview/test-animation

As you can see, the platform’s animation plays automatically when the scene is loaded because I commented this line this.model.animation.currentTime = 0;.


#5

OK sorry it was my mistake. Thanks to Mal_Duffin I figured this out by creating a sample project. I was not using the same asset for the model and the animation. If I use the same asset, I can uncheck the activate checkbox and it works as expected :+1: