When I move my player next to a wall the camera can go through.
How do I keep that from happening
Thanks
Do you mean as in 3rd person, the camera goes through the walls if you back into them or do you mean in 1st person how you can see through them if you stand very close to them?
3rd person
Thanks
For first person, I think you can do a couple things to help with that.
One, is to scale up the player collision boundary so the camera won’t get as close to the wall.
Another way is in the main camera settings, turn the clipping planes way down in the near field.
Like .001.
Maybe doing this will help you in 3rd person also.
you could give your camera a collider to detect when it touches objects. but if your camera position is calculated from the players position no sure how this affects each other.
maybe you could cache the last camera position, then let the camera move to a position relative to the player and when it collides with something use the last position. but this can lead to strange behavior for example when player steps back to “hang” camera and then strafes sideward.
another aproach could be to check for collision of the camera, then get the colliding object, calculate the difference vector and move the camera along this away from the object.
Have a look at the Unify Wiki. There is a camera script that does what you want i think.
Or search WOW camera script in the forums, also does that with raycasting.
The easiest solutions are listed in this thread. The ‘don’t go through things’ script and the ‘WOW Camera’ scripts are good.