7
\$\begingroup\$

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?

\$\endgroup\$
4
  • \$\begingroup\$ Maybe you could put a sphere collider on a parent game object of the camera? \$\endgroup\$
    – Chuck D
    Commented May 1, 2012 at 21:33
  • \$\begingroup\$ Let me try that out \$\endgroup\$ Commented May 2, 2012 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\$ Commented May 2, 2012 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\$ Commented May 2, 2012 at 19:17

2 Answers 2

8
\$\begingroup\$

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.

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

+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.

\$\endgroup\$
2
  • \$\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\$ Commented May 2, 2012 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
    Commented May 2, 2012 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .