I'm using a modified version of the standard Unity First Person Controller. At the moment when I stand near walls, the camera clips through and lets me see through the wall. I know about camera occlusion and have implemented it in 3rd person games, but I have no clue how I'd accomplish this in a first person game, since the camera doesn't move from the player at all.

How do other people accomplish this?

  • \$\begingroup\$ Maybe you could put a sphere collider on a parent game object of the camera? \$\endgroup\$ – Chuck D May 1 '12 at 21:33
  • \$\begingroup\$ Let me try that out \$\endgroup\$ – Timothy Williams May 2 '12 at 0:41
  • 2
    \$\begingroup\$ I haven't messed with the FP controller much in Unity but if your camera is passing through walls, doesn't that mean the player is passing through (or partly into) walls? Maybe the collidable component(s) of your controller need to be wider. \$\endgroup\$ – chaosTechnician May 2 '12 at 14:55
  • \$\begingroup\$ Actually, I already have a capsule on the camera, it's what is attached to the camera as a default. However it's not a parent, does the parent part matter? I'll try adding a sphere collider to it, on top of the character controller collider. \$\endgroup\$ – Timothy Williams May 2 '12 at 19:17

It's probably an issue of your near clipping plane of your camera being further away than the radius on your character controller.

Either make the collision radius bigger or make the near clipping plane smaller.

If you look in the editor at the camera frustum you can easily tell if it's too far out compared to your collision radius. Here's an example:

Notice how the rear plane is clipping through the wall.

  • \$\begingroup\$ How can I go about making the near clipping plane smaller? \$\endgroup\$ – Timothy Williams May 2 '12 at 19:22
  • 2
    \$\begingroup\$ @TimothyWilliams it's a parameter in the inspector for the camera component. \$\endgroup\$ – Tetrad May 2 '12 at 19:27

+1 to Rubber Mallet.

In "Unity 3.x Game Development Essentials" I saw the same example. Just put the camera on the top of sphere object(with collider). Also you could try to disable mesh renderer on it if you do not want to see the sphere.

  • \$\begingroup\$ I actually already have it that way, I use a charactercontroller, so it's not that that's causing the issues. I think it's what Tetrad said. \$\endgroup\$ – Timothy Williams May 2 '12 at 19:23
  • \$\begingroup\$ Actually, I was thinking of the 3rd Person Controller. I'm pretty sure Tetrad's got the right idea. \$\endgroup\$ – Chuck D May 2 '12 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.