Advertisement
Guest User

smooth follow unity 2D

a guest
May 20th, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SmoothFollow : MonoBehaviour {
  5.  
  6.     public Transform target;    // The target we are following
  7.     public float positionDamping;
  8.  
  9.     private Vector3 deltaPos;
  10.  
  11.     // Use this for initialization
  12.     void Start () {
  13.         deltaPos = new Vector3(-4f, 1f, 0f);
  14.     }
  15.    
  16.     // Update is called once per frame
  17.     void Update () {
  18.    
  19.     }
  20.  
  21.     public void FixedUpdate () {
  22.         Vector3 targetPosition = target.position - (Vector3.forward * 10);
  23.  
  24.         //transform.position = Vector3.MoveTowards(transform.position, targetPosition + deltaPos, positionDamping * Time.deltaTime);
  25.         Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, targetPosition + deltaPos, positionDamping * Time.deltaTime);    
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement