Rotate mesh with camera attached to bone

Hello! Can someone explain how to properly rotate mesh with camera attached to bone?
Babylonjs FPS (Camera to bone) | Babylon.js Playground

I am not sure to fully understand the question and what you are trying to achieve ?

Hello! i have a model with animanted bone dedicated for camera. You can see in my playground that ive attached camera to “camera” node. Now i want to rotate mesh with camera. Ive tried to do this by: character.rotation = camera.rotation; but this doesnt work as i expected :frowning:

I would do it a bit differently:

  • with mouse delta, rotate the root of the character instead of the camera
  • parent the FPS_Camera to the mesh root with an offset

Let me see if I can do something …

Yes, but i will loose camera bone animation (swing when walking)?

Nop, it depends to which bone you attach the camera. You can even add an intermediate transform.

Babylonjs FPS (Camera to bone) | Babylon.js Playground

See the top right view, there is still a swinging but the camera stays in place

The goal is to save walking animation (swing when character making steps). Sory for my english :frowning:

I see! Let me check if I can improve it.

1 Like

Looks better now : Babylonjs FPS (Camera to bone) | Babylon.js Playground

2 Likes

“You are breathtaking” :slight_smile: Can you explain changes you made? FreeCamera instead of UniversalCamera?

1 Like

It should work the same with UniversalCamera. The main difference is the way to attach to the camera coming from glb.

1 Like

As i can see, you created a FreeCamera and specified parent node as i did in 81 line (camera.parent = cameraNode;). Now, your camera works properly in viewport you created but these are created only for debug. How to make it work in main viewport?

You can add a pointer lock and change camera.rotation accordinging to mouse inputs.
Babylonjs FPS (Camera to bone) | Babylon.js Playground

using a camera is not necessary here. It should be a transform instead.

1 Like

Here it is with a simple transform node

Babylonjs FPS (Camera to bone) | Babylon.js Playground

2 Likes

Thank you for you help and explanations :+1:

Babylonjs FPS (Camera to bone) | Solution

1 Like