I have a camera that I want to toggle position and rotation on click of a button. The position toggles just fine, but the setRotation is way too confusing. When I do setRotation with angles (0,90,0) in initialization it works fine (I got this number from x,y,z of entity from editor).
But the same code on click of a button rotates to a completely weird angle. What am I missing ?
The fly-camera.js is changing the rotation every frame with itās own internal rotation values so it any external change to the rotation of the entity is going to get overwritten in the next update. Rather than trying to change the entity rotation directly, you be best off going through the fly-camera.js script properties.
eg.
var flyCameraScript = this.app.root.findByName('fpCamera').script.flyCamera;
flyCameraScript.ex = 0;
flyCameraScript.ey = 90;
(I also recommend that you keep with using the same āspaceā for rotation and positional. In the update function of the fly-camera.js, it uses localRotation and localPosition but where you are attempting to set the rotation in other places in world space. In this project, it wonāt matter but itās something to consider if you do this with others).
Ah, gotcha. Damn this killed many hours of mine !
Thank you soo much.
āI also recommend that you keep with using the same āspaceā for rotation and positionalā. Do you mean I should not use setLocalEulerAngles because it operates on parent and instead use setEulerAngles api, which operates in world space ?