Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Smooth Chase Camera for Terrain

Discussion in 'Scripting' started by Jonathan Czeck, Apr 7, 2005.

  1. Jonathan Czeck

    Jonathan Czeck

    Mar 17, 2005
    I have an idea for a camera tracking behavior that I am looking for hints on implementing:

    I'd like to apply a force to the camera as a linear function (with a defined maximum force) dependent on the camera's current position to this point:

    This point would move to be a specified distance from its target in whatever direction it needs to do so. Additionally, it would use something similar to the "Place Object On Surface" menu item to furthur position the point. Then it would offset the point by a defined "elevation" variable.

    The effect should be a smooth chase camera that follows terrain and never goes through objects.

    After writing this now, I see it would be a problem for any tall objects on the terrain, like trees.

    Can anyone offer some hints at what sections of the Script Reference would be good to look at for this? Or a better approach is most certainily welcome. :)

    I guess what I'm looking for is "lazy" object parenting with collisions, so you never go under the terrain in an ugly way.

  2. Joachim_Ante


    Unity Technologies

    Mar 16, 2005
    * Don't use rigid bodies to create a follow camera
    * Take a look at the ray cast functions in dynamics. Cast a ray downwards, to find the intersection with the terrain. Using Debug.DrawLine can save you a lot of time when debugging.
    * Quaternion.Slerp, Quaternion.FromToRotation, Quaternion.AxisAngle, Quaternion.LookRotation are your friends.

    * That said, I am going to add a sample script for follow camera to one of the next beta releases.

    Making a good follow camera that works in all cases is a hard problem. I'll try to make the follow camera as good as possible.
  3. tatelax


    Feb 4, 2010