Advertisement
artemisart

Unity3d SmoothChild

Mar 27th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class SmoothChild : MonoBehaviour
  4. {
  5.     public Transform target;
  6.     public float posDampingTime = 5;
  7.     public float rotDampingTime = 5;
  8.    
  9.     void LateUpdate ()
  10.     {
  11.         Vector3 fromPos = transform.position;
  12.         Vector3 toPos = target.position;
  13.         Vector3 newPos = posDamping > 0 ?
  14.             Vector3.Lerp (fromPos, toPos, Time.deltaTime / posDampingTime) :
  15.             toPos;
  16.        
  17.         Quaternion fromRot = transform.rotation;
  18.         Quaternion toRot = target.rotation
  19.         Quaternion newRot = rotDamping > 0 ?
  20.             Quaternion.Lerp (fromRot, toRot, Time.deltaTime / rotDampingTime) :
  21.             toRot;
  22.        
  23.         transform.position = newPos;
  24.         transform.rotation = newRot;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement