Search Unity

Camera Offset from terrain

Discussion in 'Scripting' started by My Name Is [...], Jan 4, 2014.

  1. My Name Is [...]

    My Name Is [...]

    Joined:
    Jun 19, 2013
    Posts:
    24
    I want to move my camera forward and the camera won't go through the terrain

    $Moving Camera.PNG
     
    Last edited: Jan 4, 2014
  2. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    Cast a ray downwards to see the terrain position on y axis at your current camera position on x axis. To that value add your camera offset constant. The resulting value is the y axis position you want for camera so update it for camera on each physics tick.

    camera.y = terrainYAtX(camera.x) + offset
     
    Last edited: Jan 4, 2014