1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  3. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
    Dismiss Notice
  4. Unity 5.5 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  6. Unity 5.6 beta is now available for download.
    Dismiss Notice
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
    Dismiss Notice
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.
    Dismiss Notice

Smooth Chase Camera for Terrain

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

  1. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Messages:
    1,713
    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.

    Thanks
    -Jon
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Messages:
    3,709
    * 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

    tatelax

    Joined:
    Feb 4, 2010
    Messages:
    1,142