Animation currentTime

Hello, i want to change the time of release of the arrow from the start of animation to a given time of animation so i tried if (this.state===‘shot’ && this.model.animation.currentTime===‘0.3’) { //shot arrow}
but it don’t work, i think i misused the currentTime how do i correct that?

It is VERY unlikely that the currentTime will be exactly any particular value when you check it (also not sure why you are you checking against a literal string?). Something like this should work:

if (this.state === 'shot' && this.model.animation.currentTime >= 0.3) {
    // shot arrow
    this.state = 'afterShot'
}

This can’t do coz the animation last 0.46 so every time after 0.3 it will shot an arrow…i will get a gathling instead a bow lol

Ops just noticed the aftershot :stuck_out_tongue: this may work uhm.
Your solution worked very well :slight_smile: thanks a lot

Anyone, please help!! Here is my code. I simply want to go to the smash animation after the idle animation. What am I doing wrong??

var AnimationBlending = pc.createScript('animationBlending');

AnimationBlending.states = {
    idle: {
        animation: 'idle.json'
    },
    punch: {
        animation: 'smash.json'
    }
};

// initialize code called once per entity
AnimationBlending.prototype.initialize = function() {
    this.blendTime = 0.4;

    this.setState('idle');

};

AnimationBlending.prototype.setState = function (state) {
    var states = AnimationBlending.states;

    this.state = state;
    // Set the current animation, taking 0.2 seconds to blend from
    // the current animation state to the start of the target animation.
    this.entity.animation.play(states[state].animation, this.blendTime);
};


AnimationBlending.prototype.update = function(dt) {
    if (this.state === 'idle' && this.currentTime >= 3) {
        // shot arrow
        this.setState('smash');
    }
};

Code on its own is no much use in most cases, make simple example project with replication of issue and share it. This helps others to debug your problem.

Here is the Link:

https://playcanvas.com/project/443374/overview/projectmorpheus

It’s a public project!

You animation.js file should be:

var AnimationBlending = pc.createScript('animationBlending');

AnimationBlending.states = {
    idle: {
        animation: 'idle.json'
    },
    smash: {
        animation: 'smash.json'
    }
};

// initialize code called once per entity
AnimationBlending.prototype.initialize = function() {
    this.currentTime = 0;
    this.blendTime = 0.4;

    this.setState('idle');

};

AnimationBlending.prototype.setState = function (state) {
    var states = AnimationBlending.states;

    this.state = state;
    // Set the current animation, taking 0.2 seconds to blend from
    // the current animation state to the start of the target animation.
    this.entity.animation.play(states[state].animation, this.blendTime);
};


AnimationBlending.prototype.update = function(dt) {
    this.currentTime += dt;
    if (this.state === 'idle' && this.currentTime >= 3) {
        // shot arrow
        this.setState('smash');
    }
};

Do a visual difference between your file and the code above to see what fixes I had to make.