I am currently working on Anim State and have encountered some issues. I want to trigger animations with some simple keyboard keys, and each animation is non looping. I am not sure how to execute the animation from the first frame again with a keyboard keys.
To add, ‘execute the animation from the first frame again with a keyboard key’ means that I want to restart the animation using the same keyboard button. For example, if key 1 starts animation 1, then when animation 1 is completed, I can use key 1 to restart it again
One more question:Can animations be set to reverse by script?
Anim State Graph Test - PLAYCANVAS
var TestAsgcontrol = pc.createScript('testAsgcontrol');
TestAsgcontrol.attributes.add('targetEntity', {
type: 'entity'
});
// initialize code called once per entity
TestAsgcontrol.prototype.initialize = function () {
this.graphNum = 0;
};
// update code called every frame
TestAsgcontrol.prototype.update = function (dt) {
if (this.app.keyboard.wasPressed(pc.KEY_1)) {
this.targetEntity.anim.setBoolean('asgc1', false);
this.targetEntity.anim.setBoolean('asgc2', false);
this.targetEntity.anim.setBoolean('asgc1', true);
this.graphNum = 1;
}
if (this.app.keyboard.wasPressed(pc.KEY_2)) {
this.targetEntity.anim.setBoolean('asgc1', false);
this.targetEntity.anim.setBoolean('asgc2', false);
this.targetEntity.anim.setBoolean('asgc2', true);
this.graphNum = 2;
}
if (this.app.keyboard.wasPressed(pc.KEY_P)) {
// pause
this.targetEntity.anim.speed = 0;
}
if (this.app.keyboard.wasPressed(pc.KEY_S)) {
// start
this.targetEntity.anim.speed = 1;
}
// restart
if (this.app.keyboard.wasPressed(pc.KEY_R)) {
}
};
// swap method called for script hot-reloading
// inherit your script state here
// TestAsgcontrol.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/