Search Unity

Bumpy Camera Problem

Discussion in 'Scripting' started by yair1221, Jan 28, 2012.

  1. yair1221

    yair1221

    Joined:
    Sep 28, 2011
    Posts:
    39
    I made a camera script to fit my flight sim game, but the problem is, the camera is always a bit bumpy...meaning it moves in flashes, the camera itself is using LateUpdate and every other script is using Update...
    here it goes:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameraScript : MonoBehaviour {
    5. public Transform target;
    6. public Vector3 pos;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.    
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void LateUpdate () {
    15.        
    16.         if(target)
    17.         {
    18.             var wantedpos = target.position;
    19.             wantedpos += target.right * pos.x;
    20.             wantedpos += target.up * pos.y;
    21.             wantedpos += target.forward * pos.z;
    22.             transform.position = Vector3.Lerp(transform.position, wantedpos, target.rigidbody.velocity.sqrMagnitude + 0.1f);
    23.             transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, 0.1f);
    24.         }
    25.    
    26.     }
    27. }
    28.  
    i figured that the problem must be the object moving AFTER the camera, but that cant be right, as the camera is in late update, can anyone help? this is kinda screwing things up...i also tried changing everything else to FixedUpdate, showed a little improvment but didnt work either...
     
  2. yair1221

    yair1221

    Joined:
    Sep 28, 2011
    Posts:
    39
    *bump*