Jump to content

RPG camera


TomaszFurca
 Share

Recommended Posts

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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...