- Home /
How to make that the camera will not go through the walls?
I have the camera attached to the player but when i'm rotating the player the camera go through the walls. Is it possible to make the camera collide with the walls. //Sorry for my english
Answer by TSI25 · Jan 15, 2018 at 08:19 PM
So theres a couple algorithms/approaches for this but there isnt really a straightforward and super easy solution. I prefer the 'Whiskers' approach used in Journey that you can learn more about HERE.
Essentially he breaks it down into 2 approaches, the first is to use a raycast from the camera to the player, and if that hits an object that would occlude the player then you push the camera closer to the player until its no longer occluding. The other approach is to raycast in a radius from the camera and sort of push the camera around a little more subtley to avoid occlusion. probably for your purposes the first solution will be a little bit more approachable and have a more desirable result.
Definitely watch that whole video if you have the time though, it has a lot of great insights into best practice camera controls.