// Update is called once per frame
 void Update()
 {
     if (Transforms.Length > 1)
     {
         if (BenjasMath.countdownToZero(ref timeToNext))
         {
             factor     = (float)animationTime * (1 + Mathf.Lerp(-aniTimeVariation, aniTimeVariation, Random.value));
             timeToNext = factor;
             origin     = target;
             target++;
         }
         if (target >= Transforms.Length)
         {
             target = 0;
         }
         float t;
         t = BenjasMath.easeInOut(1f - timeToNext / factor);
         transform.position = Vector3.Lerp(Transforms[origin].position, Transforms[target].position, t);
         t = BenjasMath.easeInOut(1f - rotationSpeedup * timeToNext / factor);
         transform.eulerAngles = BenjasMath.angularLerp(Transforms[origin].eulerAngles, Transforms[target].eulerAngles, t);
     }
     else
     {
         this.enabled = false;
     }
 }
Example #2
0
    void doDocking()
    {
        float t = Mathf.Pow(Mathf.InverseLerp(dockingDuration, 0, dockingTime), 1);

//		float t2 = Mathf.Clamp01(Mathf.InverseLerp(dockingDuration,dockingDuration-1,dockingTime));



        //lerp the position
        transform.position = Vector3.Lerp(transform.position, nextDockingPoint.position, t);
        //lerp the rotation
        transform.eulerAngles = BenjasMath.angularLerp(transform.eulerAngles, nextDockingPoint.eulerAngles, t);
        // lerp the velocity
        //rigi.velocity = Vector3.Lerp(rigi.velocity ,  Vector3.zero,   t2);

        float dist        = Vector3.Distance(transform.position, nextDockingPoint.position);
        float angularDist = Vector3.Distance(transform.eulerAngles, nextDockingPoint.eulerAngles);

        //test if docking time is over or position is close enough (10mm and 1/10°)
        if (BenjasMath.countdownToZero(ref dockingTime) || (dist < 0.01 && angularDist < 0.1))
        {
            finishDocking();
        }
    }