FollowCamera with Collisions

Hello, I am coding a game and managed to get a mesh ground working. My scene is rendered by a FollowCamera that follows the player (both his position and direction), making the game a third-person game.

However, I am encountering an issue: whenever the player moves on a slope, the camera continues to follow him and ends up below the ground mesh, which looks very bad. Having the camera use a move with collision would be great, but I couldn’t find how for a FollowCamera. Do I need to change my camera to a FreeCamera, though losing the properties of the FollowCamera would be a loss?

Overall, what is the way to proceed there to have the camera continue following the player but also avoid it getting into other meshes?

Thanks a lot for reading me!

You may cast a ray from camera to detect if any mesh is too close to it, then use some logic to avoid your issues. Mesh Picking | Babylon.js Documentation

Also, have a look how this problem is solved here - GitHub - ssatguru/BabylonJS-CharacterController: A CharacterController for BabylonJS


Thanks a lot! :smile:

1 Like