Mesh rotate with camera rotate

Hello everyone. I am engaged in switching between first and third person camera. There are problems with the first person camera. I would like the direction of the character to change in the same way as the direction of the camera. Now this is already working, but for some reason the character rotation lags far behind the camera rotation. I think the code you want starts on line 64

https://playground.babylonjs.com/#064K5R

Adding @Cedric and @RaananW as I can see you are using physics as well as moveWithCollisions: I don’t know if those are compatible…

1 Like

The problem in your playground is that you set the camera’s parent to be the mesh, and then compare the rotations of both and change the rotation of the mesh according to the camera. so the rotation to the camera is actually applied twice - once by its parent, and once as defined by the camera. You will need to rethink the parenting system (or the need of one)

2 Likes

Yes, it works.
https://playground.babylonjs.com/#064K5R#4

I removed the camera’s dependency on the mesh and instead listened to the position and rotation of the character through the observable.

But I have a question. How reasonable is the approach I have taken? And, if I may, there is one more question. In third person view, I would not want the camera to fly through the wall. I would like it to always remain indoors and scaled if i hit the wall with the camera. What are the options to achieve this?