Simple Animation Blend

Hi,

I’ve created two animated elements, a dummy object that follows a path and a character with a simple walk cycle. I was hoping to be able to parent one to the other but this approach doesn’t seem to work. I’ve made a simple scene to illustrate what i’m trying to do, the box isn’t animated in this instance but it still doesn’t follow its parent.

Any ideas? Maybe i’m just coming at this from the wrong angle.

https://playcanvas.com/editor/scene/607533

Thanks,

SF

Am I correct in saying that you want the large box to be in the same position as the arrow mesh?

If so, making it a child won’t work as the entity that has the animated model doesn’t move, it’s the mesh that is moving.

What you can do is get the graphNode of the animated mesh in the entity ‘SK_Path’. If you look at the children of the entity ‘SK_Path’, you should seethe Box entity and graph nodes of the model.

On the post update, you can set the position of the Box entity to be the same as the animated graphNode.

Hi Yaustar,

Thanks for the quick reply, I’m still having trouble finding the node within SK_Path that actually moves, I’ve tried a few things the latest of which is this, i’m just logging the result so i can see the change;

could i have another nudge in the right direction please.

// initialize code called once per entity
FollowMesh.prototype.initialize = function() {
    
    var childEntity = this.entity;
    var parentEntity = childEntity.parent;
    this.model = parentEntity.model;
    console.log(this.model);
    
};

// update code called every frame
FollowMesh.prototype.update = function(dt) {
    console.log(this.model.entity.position);
};

In the console, print out all the names of the children graphNodes of ‘SK_Path’. You should see one being ‘Box’ and another the name of the mesh instance that is being animated.

I only see the Box and a second GraphNode called RootNode, I’ve checked and this doesn’t move either.

    var childEntity = this.entity;
    var parentEntity = childEntity.parent;
    this.children = parentEntity.children;
    console.log(this.children);

Looks like there were several more children under RootNode. This is the ‘working’ version https://playcanvas.com/editor/scene/607789

See app.js

(Note that I’ve unparented the Box entity)

Thanks that’s really helpful!

Out of interest how did you see the other nodes? Or was i just missing them. I was logging out the array but could only see two?

I logged the children and just kept expanding the children of the children etc in the console view.

Must have just missed it. thanks for your help.