- Home /
Player Follow Camera Goes Inside Objects
I was working on a 3d game where the camera is continuously following the player object in position and rotation fields.
Complete 3d environment is set up as per my gameplay. A player moves and rotates in different areas of the environment, I was getting this kind of abnormal view in front of the screen. The camera goes into the other objects.
This is a really poor gameplay experience so how to fix this? How to make this look better when the player following the camera goes inside other environment objects?
Answer by screensmith · Nov 22, 2019 at 05:35 PM
You need to add collision to your camera and make sure that it doesn't enter 3D objects. When I made a 3d character controller I followed this tutorial to do this with raycasting. In update you can raycast behind the player a couple meters and place the camera at the end of the ray, that way if something is behind the player the ray will hit that object and place the camera in front of the object, not inside of it.
I think I require to watch the above video to understand your point in a better way :)
the logic screensmith is describing is simplified as:
if (camera is inside object) { move camera closer to the player }
@binaryprogrammer - overall logic becomes really important to me and I have implemented the concept in my way.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215153im_/https://answers.unity.com/themes/thub/images/avi.jpg)