hey everyone
I want to attach a camera to an fbx file containing animation.
however it seems that the camera is just stuck on the origin of the scene ,what am I doing wrong?
heres my code:
var CamerTest = pc.createScript('camerTest');
// initialize code called once per entity
CamerTest.prototype.initialize = function() {
};
// update code called every frame
CamerTest.prototype.update = function(dt) {
var camTarget1 = this.app.root.findByName('camTest');
var maxObject = camTarget1.model.model.graph.findByName('Camera');
var camPosition = maxObject.getPosition();
var camRotation = maxObject.getEulerAngles();
console.log("postion: " + camPosition);
console.log("rotation: " + camRotation);
this.entity.setPosition(camPosition);
this.entity.setEulerAngles(camRotation);
};
If I attach my script to camTest and perform your suggestion, my camera just attach itself to the pivot point of the animated object and rotates like crazy. its not following along the actual object.
It would be great if you do that @linelineline. In fact, now that I understand your intent, if you add me to the project, I can try to help you fix it. Username - tester29.
also is it possible to animate the rotation of the camera? I dont wish for it to be controlled by input but rather just rotating alongside a pretermined set of coordinates
The issue was that the script wasnāt using the animated graphNode in the camTest model and also the position/rotation of the animated node wasnāt being given to the camera.
Script:
var CamerTest = pc.createScript('camerTest');
CamerTest.attributes.add('followObject', {type: 'entity'});
// initialize code called once per entity
CamerTest.prototype.initialize = function() {
this.camTarget1 = this.entity.findByName('Sphere');
};
// update code called every frame
CamerTest.prototype.update = function(dt) {
var camPosition = this.camTarget1.getPosition();
var camRotation = this.camTarget1.getEulerAngles();
this.followObject.setPosition(camPosition);
this.followObject.setEulerAngles(camRotation);
};