TomaszFurca Posted October 5, 2018 Share Posted October 5, 2018 Today i working with cameras in my game. I am confused about correct solution to do that as best as possible, generally in performance. I have two camera first for GUI, second for objects render with post processing. For every position change of my player i must update position for two cameras like that: const camera = this.game.getScene().getCameraByName('gameCamera'); const guiCamera = this.game.getScene().getCameraByName('GUICamera'); const newPosition = this.meshForMove.position.clone(); camera.position = newPosition.clone(); camera.position.y = 30; camera.position.z -= 22; camera.position.x -= 22; guiCamera.position = newPosition.clone(); guiCamera.position.y = 30; guiCamera.position.z -= 22; guiCamera.position.x -= 22; I must update twice cameras, because onPointerDown event return PickPoint from GUICamera, because it is registered as second active camera. I use that code in function in registerBeforeRender, when player moves. Also i tried with box, which was children of my character mesh and parent of my cameras, but when my character change rotation, then cameras lost correct position. I don't know how keep correct position using parent system. Maybe someone have idea how do that better? Thanks Tom Quote Link to comment Share on other sites More sharing options...
kcoley Posted October 5, 2018 Share Posted October 5, 2018 Hi @TomaszFurca, do you have a sample playground that demos your issue? Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted October 5, 2018 Share Posted October 5, 2018 Hi, Why do you have a seperate camera for the GUI ? Quote Link to comment Share on other sites More sharing options...
TomaszFurca Posted October 6, 2018 Author Share Posted October 6, 2018 @aWeirdo I separate camera for GUI, because i use post processing , then 2d textures are blurred for example. @kcoley Just look at this playgrounds: Correct camera position, but in this example rotation of player (box2) is not changed https://playground.babylonjs.com/#199KHL#39 In this example I add rotation and just look what happen with camera https://playground.babylonjs.com/#199KHL#40. I want to keep camera rotation and position from #39 example even when player change rotation. Quote Link to comment Share on other sites More sharing options...
Guest Posted October 8, 2018 Share Posted October 8, 2018 Hello you can force the first camera to be used for picking: scene.cameraToUseForPointers = myCamera So in this case no need to sync the second camera. Can you elaborate a bit more regarding the camera parent question? If the camera is child of a mesh which is rotating then the camera will rotate, this is expected. Quote Link to comment Share on other sites More sharing options...
TomaszFurca Posted October 8, 2018 Author Share Posted October 8, 2018 This option for camera is that what i looking for! In 40 example when player change rotation then cameraBox change position , this is excepted I know. But i ask about is possible to always keep camera in position like in 39 example, even if i change position of parent? Maybe using parent system i need do write too much logic and my actual idead about clone position is better than parent system. Just looking for best solution for RPG camera. Quote Link to comment Share on other sites More sharing options...
Guest Posted October 8, 2018 Share Posted October 8, 2018 Yes definitely. parenting is not a good option for that TomaszFurca 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.