Example #1
0
 public void TestAim()
 {
     if (Mathf.Abs(targetSpeed.Speed) < 0.01f)   //物体的速度过小,则默认物体是静止的。
     {
         isAim  = true;
         aimPos = target.position;
     }
     else
     {
         targetDir = transform.position - target.position;
         angle     = Vector3.Angle(targetDir, targetSpeed.CurrentVector);
         distence  = targetDir.magnitude;
         float a = PhycisMath.GetPom((rocketSpeed.Speed / targetSpeed.Speed), 2);
         float b = PhycisMath.GetRad(distence, angle);
         float c = distence * distence;
         float d = PhycisMath.GetDelta(a, b, c);
         isAim = d >= 0 && !float.IsNaN(d) && !float.IsInfinity(d);
         if (isAim)
         {
             float r = PhycisMath.GetSqrtOfMath(a, b, d);
             if (r < 0)
             {
                 isAim = false;       //如果得出的是负值,则代表交点有误
             }
             aimPos = target.transform.position + targetSpeed.CurrentVector * r;
         }
     }
 }
Example #2
0
 void Update()
 {
     dtime = Time.time - lastTime;
     if (dtime > 0)
     {
         lastTime      = Time.time;
         Speed         = PhycisMath.GetSpeed(lastPos, transform.position, dtime);
         CurrentVector = PhycisMath.GetDir(lastPos, transform.position);
         if (Mathf.Abs(Speed) < 0.001f)
         {
             CurrentVector = transform.TransformDirection(Vector3.forward);
         }
         lastPos = transform.position;
     }
 }