Search code examples
unity-game-engineperspectivecamera

Unity3D : LineRenderer cut by camera


I use a LineRenderer to represent a "laser beam" in my game.

However, when the beam goes backwards (ie. the end point is behind the player), the camera cuts the line.

A screenshot to explain the situation :

LineRenderer cut by camera

In blue : my laser beam. In dashed red : the behavior I want.

As I see it, the problem is that the camera is a rectangle, and not a zero dimension point (as is the human eye, more or less).

Is there a way to cheat this and get the line to go to the edge of the screen ?


Solution

  • Make the near clip plane smaller. But this will increase the chances of z-buffer conflict (you will see some weird shapes on textures).

    Near clip plane pretty much ignores anything closer to the camera than that value and same for far clip plane. So by making it 0.01 (smallest value), you get to see more. But again, z-buffer is getting a big hit and you will start seeing some black semi-transparent shape here and there. You can limit that effect by reducing the far clip plane. So it is just a matter of finding the right values.