Camera SetParent Really Needed

Yo @Deltakosh or @sebavan … I really really really need to parent a camera and have it stay in the same spot like you would a mesh using setParent. Is really no other this can be accomplished ? Heck, even some MacGuyver stuff if it does the job.

So @Deltakosh or @sebavan, I MacGuyver together some shit that works, if anybody else needs to do the same.

First I am using a proxy transform node called cameraTransform. I set that to the walk camera’s global position and rotation, make the walk camera a child of the cameraTransform proxy and zero it out. Then use the cameraTransform.setParent(obj, true, true) to make it stay in same space when finally parented to my player transform… Looks great so far. Do you see any issues with this code:

this.cameraTransform.parent = null;
this.cameraTransform.position.copyFrom(this.walkCamera.position);
this.cameraTransform.rotation.copyFrom(this.walkCamera.rotation);

this.walkCamera.parent = this.cameraTransform;
this.walkCamera.position.set(0, 0, 0);
this.walkCamera.rotation.set(0, 0, 0);

this.cameraTransform.setParent(this.playerTransform, true, true);
1 Like

You have a good solution there but I agree we could add it to the cameras. Please file an issue for me in the repo. I will do it when I’m done with my current task

3 Likes

After looking in depth, it appears that your solution is by far the best. If I had to add it to the camera I would have to go to all cameras and do specific code as they do not share a central structure (like position / rotation etc…).

So closing the issue as your solution is the best one

2 Likes

Thanks @Deltakosh