[SOLVED] Why aren't my animations working?

I’ve linked the entity to the ‘modelEntity’ attribute, but the animations aren’t working… I had them working yesterday so I know that the state graph is working, plus I’ve rewritten the state graph 3 times.

var PlayerController = pc.createScript('playerController');

PlayerController.attributes.add('power', { type: 'number' });

PlayerController.attributes.add('jumpHeight', { type: 'number' });

PlayerController.attributes.add('modelEntity', { type: 'entity' });

PlayerController.prototype.initialize = function() {
    this._anim = this.modelEntity.anim;
    this._angle = 0;
    this.baseAngle = 0;
    this.yVel = 0;
};

PlayerController.prototype.update = function(dt) {
    var x = 0;
    var z = 0;
    if (this.yVel > 0) {
        this.yVel -= 3;
    }
    if (this.app.keyboard.isPressed(pc.KEY_W)) {
        x -= 1;
    }
    if (this.app.keyboard.isPressed(pc.KEY_S)) {
        x += 1;
    }
    if (this.app.keyboard.isPressed(pc.KEY_A)) {
        z -= 1;
    }
    if (this.app.keyboard.isPressed(pc.KEY_D)) {
        z += 1;
    }
    /*if (this.app.keyboard.isPressed(pc.KEY_LEFT)) {
        this.baseAngle += 10;
        this.fire('base angle', this.baseAngle);
    }
    if (this.app.keyboard.isPressed(pc.KEY_RIGHT)) {
        this.baseAngle -= 10;
        this.fire('base angle', this.baseAngle);
    }*/
    if (this.app.keyboard.wasPressed(pc.KEY_SPACE) && this.entity.rigidbody.linearVelocity.y === 0) {
        this.yVel = this.jumpHeight;
    }
    this.entity.rigidbody.applyForce(0, this.yVel, 0);
    let movement = new pc.Vec3(-x * Math.sin(this.baseAngle * Math.PI / 180) - z * Math.cos(this.baseAngle * Math.PI / 180), 0, -x * Math.cos(this.baseAngle * Math.PI / 180) - z * Math.sin(this.baseAngle * Math.PI / 180)).normalize().scale(dt * this.power);
    this.entity.rigidbody.applyForce(movement);
    if(x !== 0 || z !== 0) {
        this._angle = pc.math.lerpAngle(this._angle, 180 + (Math.atan2(z, x) * pc.math.RAD_TO_DEG), 0.4) % 360;
        this.modelEntity.setEulerAngles(0, this._angle, 0);
    }
    else {
        this._angle = pc.math.lerpAngle(this._angle, this.baseAngle, 0.4) % 360;
        this.modelEntity.setEulerAngles(0, this._angle, 0);
    }
    this.modelEntity.anim.setFloat('Speed', Math.abs(x+z));
    this.modelEntity.anim.setFloat('Jump', this.yVel > 0 ? 1 : 0);
};

Hi @P0werman1! What is the current result? T-pose? Can you share the editor link of your project please?

https://playcanvas.com/project/1036368/overview/game
Yes, it just T-poses

The root bone on the anim component is set incorrectly. It needs to be on:

If you open the animation into the viewer, you can see the animation hierarchy:

image

It expects a child node called Root to be under the RootBone/Node.

This video covers debugging issues like this:

1 Like

Thank you! It works now.