Attach camera to animated model for movement

Hello all,

Is it possible to attach a camera to an imported model that includes animation?

IE. can i animate a box object in 3DMax and then use it’s animation to set a camera path in Canvas?

I did a simple test and it does not seem to work but maybe it just needs a script to update the position each frame to match the box object position.

Does just setting the camera entity as a child of your animated entity not work?

I was able to get the position every frame of an animated character’s feet to create snow prints, you can check that out here:

https://playcanvas.com/project/499377/overview/snow-test

The snow doesn’t work very well yet but you can see how I get the position of the wolf’s paws in WalkControls.js

 var wolfModel = this.entity.findByName("Wolf_Model");
 var paws = ["Vorderpfote_R","Vorderpfote_L","Pfote2_L","Pfote2_R"];
    
    
 for(var i=0;i<paws.length;i++){
     var p = wolfModel.model.model.graph.findByName(paws[i]);
     var pos = normalizeCoords(p.getPosition());
     ....rest of code...
}

Hi Omar,

Thanks for the input… I will take a look at the code and see if i can make it work.

I tried the camera as a child of the animated model entity first but it does not work… the child camera just sits static at the starting position of the animated model.

Ok… i kind of have it working. The child camera entity follows the model animation not but the camera is pointing down and not aligned to the x,y,z angles of the parent entity model.

I’ve tried variations on getRotation, getLocalRotaion, and getEulerAngles but they all rotate the camera to point straight down when set. I’ve also tried rotating the object in 3dMax before importing and it had no effect on the rotation alignment.

Here is a test project with just the animated 3DMax model object and the simple script that updates the position and rotation of the camera to match the object every frame.

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

var camRotation = maxObject.getEulerAngles().clone();

You are getting the rotation from the animated model (CamBox), not the parent entity (camTest). Was this the intention?