Enabling and Disabling Animation

I have event handlers for the keyUp and keyDown events. But for some reason I cannot set an entity animation to enabled or activate. Should the event handlers check for pc.input.KEY_* or pc.KEY_*? Neither seems to work.

Event handler registration:

context.keyboard.on(pc.EVENT_KEYDOWN, this.keyDown, this);
context.keyboard.on(pc.EVENT_KEYUP, this.keyUp, this);

Event handlers:

    // Enable Animation
    keyDown: function(e) {
        if (e.key === pc.input.KEY_SPACE) {
            this.entity.animation.enabled = true;
            this.entity.animation.activate = true;
        }
    },


    // Disable Animation
    keyUp: function (e) {
        if (e.key === pc.input.KEY_SPACE) {
            this.entity.animation.enabled = false;
            this.entity.animation.activate = false;
        }
    }

Thank you.

Use this.entity.animation.play("animation name", blendTime); to start playing an animation. The docs are here.

enabled will enabled and disable the component completely.
activate determines whether the first animation starts playing when the game first starts.

Thanks Dave.

Yes, after reading the docs, which I did the Animation today and just completed the Camera Component, I realized that Activate wouldn’t work at all :smile:

I must say, I played with the Camera Viewport just now, that is, having two cameras render in split screen mode, and it worked rather well. Of course “we” don’t have much in the way of geometry so am I anxious to see how that plays out. When rendering multiple viewports will the depth buffer, and color buffer be pegged to each viewport size? In other words will the render targets be size accordingly?

Another nice feature of PlayCanvas is support for collaboration. Again, something we just started testing today. We need to see how this plays out. Btw, I have an invitation still pending even though I sent it twice. I sent two different invitations out, one worked the other didn’t. Then I resent the second invitation, and sent it third time still. On the third try PlayCanvas stated that an invitation was outstanding and wouldn’t allow me to send it again.

A different question altogether, something we are trying now: what about controlling different parts of a model? In modeling tools you can see the different parts of an object but PlayCanvas groups it as one. As mentioned already, still going through the documentation, but we are trying different things in parallel.

Our task at hand requires controlling different parts of the model but I don’t see how that’s done. Do you have a link readily available that you can refer me too?

Re: Controlling different parts of the model. We don’t display them in the Editor, but all the nodes that you have created in your modelling application are accessible in your scripts.

Off the top of my head something like this should work:

var model = this.entity.model.model;
var graph = model.getGraph();
var node = graph.findByName("LeftArm");
var armPosition = node.getPosition();

Thanks again Dave.

I’ll give that a try a little later and let you know if I have any problems.