Search Unity

SmoothFollow At Locked Distance

Discussion in 'Scripting' started by pi3rc3, Aug 30, 2011.

  1. pi3rc3

    pi3rc3

    Joined:
    Aug 25, 2006
    Posts:
    8
    Hey I'm trying to setup to have my camera follow a spaceship at a set distance ( in 3d space). So the camera would always be a certain distance behind but would 'smooth follow' the other axis. My problem is that right now the smooth follow starts to fall way behind the ship when it starts moving fast. Heres the SmoothFollow script I'm using http://www.unifycommunity.com/wiki/index.php?title=SmoothFollow2

    I've been banging my head against my desk for days trying to figure this out any insight or pointers will be greatly appreciated.
     
    Last edited: Aug 30, 2011
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Force the distance....

    Code (csharp):
    1.  
    2. // at the end of the Update.
    3.     transform.position=target.position;
    4.     transform.Translate(-Vector3.forward * distance);
    5.  
    And this stuff should be put into the LateUpdate, not the Update. ;)
     
  3. pi3rc3

    pi3rc3

    Joined:
    Aug 25, 2006
    Posts:
    8
    thanks that worked but when i put it in LateUpdate the camera has a constant little shake to it until it stops moving
     
  4. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Hmmm.... Migrate the camera script to the player controller. Reference the camera as Camera.main.transform