Advertisement
benimaru

Chaining iTweens to extend linear movement

Feb 7th, 2012
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1.     void Start()
  2.     {
  3.         EaseIn();
  4.     }
  5.    
  6.     void EaseIn()
  7.     {
  8.         easeInDestinationPoint = Vector3.MoveTowards(transform.position, destinationPoint, easeInDistance);
  9.         easeOutDestinationPoint = Vector3.MoveTowards(destinationPoint, transform.position, easeOutDistance);
  10.         iTween.MoveTo(
  11.             gameObject,
  12.             iTween.Hash(
  13.                 "position", easeInDestinationPoint,
  14.                 "speed", speed,
  15.                 "easetype", easeInType,
  16.                 "oncompletetarget", gameObject,
  17.                 "oncomplete", "LinearMovement"));
  18.     }
  19.    
  20.     void LinearMovement()
  21.     {
  22.         linearSpeed = Vector3.Distance(transform.position, lastPosition);
  23.        
  24.         iTween.MoveTo(
  25.             gameObject,
  26.             iTween.Hash(
  27.                 "position", easeOutDestinationPoint,
  28.                 "speed", (Mathf.Sqrt(linearSpeed)*60f),
  29.                 "easetype", iTween.EaseType.linear,
  30.                 "oncompletetarget", gameObject,
  31.                 "oncomplete", "EaseOut"));
  32.     }
  33.    
  34.     void EaseOut()
  35.     {
  36.         iTween.MoveTo(
  37.             gameObject,
  38.             iTween.Hash(
  39.                 "position", destinationPoint,
  40.                 "speed", speed,
  41.                 "easetype", easeOutType,
  42.                 "oncompletetarget", gameObject,
  43.                 "oncomplete", "OnMoveComplete"));
  44.     }
  45.    
  46.    
  47.     public float linearSpeed;
  48.     private Vector3 lastPosition = Vector3.zero;
  49.     void LateUpdate()
  50.     {
  51.         lastPosition = transform.position;
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement