Camera Offset from terrain

I want to move my camera forward and the camera won’t go through the terrain

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