乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      1.控制朝向transform.LookAt(target.transform); 2.實(shí)現(xiàn)跟隨,逐漸靠...

       有趣的永 2015-08-23
      1.控制朝向transform.LookAt(target.transform);

      2.實(shí)現(xiàn)跟隨,逐漸靠近



      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20


      GameObject player;


      float MAX_MOVE_DISTANCE=500.0f;

      void FixedUpdate()


      {


           float moveDistance=MAX_MOVE_DISTANCE*Time.deltaTime;


           Vector3 source=transform.position;


           Vector3 target=player.transform.position;


           Vector3 seekVelocity=Seek(source,target,moveDistance);


          seekVelocity=UsefulFunctions.ClampMagnitude(seekVelocity,moveDistance);


           rigidbody.AddForce(seekVelocity,ForceMode.VelocityChange)


      }

      Vector3 Seek(Vector3 source,Vector3 target,float moveDistance)


      {


              Vector3 directionToTarget=Vector3.Normalize(target-source);


              Vector3  VelocityToTarget=moveDistance*directionToTarget;


              transform.LookAt(player.transform);


              return velocityToTarget-rigidbody.velocity;  //注意,這里是向量相減


      }






      3.對(duì)2進(jìn)行優(yōu)化,提供一個(gè)更簡(jiǎn)單的方法



      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11


      Transform player;


      float speed=5.0f;



      void Update()


      {


              transform.LookAt(player);


              float distance=speed*Time.deltaTime;


              Vector3 source=transform.position;


              Vector3 target=player.position;


              transform.position=Vector3.MoveTowards(source,target,distance);


      }



      4.實(shí)現(xiàn)接近目標(biāo)時(shí)通過(guò)減速改善到達(dá)行為


      將2中的Seek替換如下:



      1

      2

      3

      4

      5

      6

      7

      8

      9

      10


      float DECELERATION_FACTOR=0.6f;



      Vector3 Arrive(Vector3 source,Vector3 target)


      {


             float distanceToTarget=Vector3.Distance(source,target);


             Vector3 directionToTarget=Vector3.Normalize(target-source);


              float speed=distanceToTarget/DECELERATION_FACTOR;


              Vector3 velocityToTarget=speed*directionToTarget;


              return velocityToTarget-rigidbody.velocity;


      }





      5.實(shí)現(xiàn)和目標(biāo)之間保持一定的距離


      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19


      float DECELERATION_FACTOR=0.6f;


      float FLEE_RADIUS=14f;


      float SEEK_RADIUS=6f;



      Vector3 adjustVelocity=Vector3.zero;


      float distanceToTarget=Vector3.Distance(target,source);


      if(distanceToTarget<FLEE_RADIUS)


         adjustVelocity+=Flee(source,target);


      if(distanceToTarget>SEEK_RADIUS)


         adjustVelocity+=Arrive(source,target);  //這個(gè)是用上面的函數(shù)

      private Vector3 Flee(Vector3 source, Vector3 target)


      {


              float distanceToTarget=Vector3.Distance(target,source);


              Vector3 directionAwayFromTarget=Vector3.Normalize(source-target);


              float speed=(FLEE_RADIUS-distanceToTarget)/DECELERATION_FACTOR;


              Vector3 velocityAwayFromTarget=speed*directionAwayFromTarget;


              return velocityAwayFromTarget;


      }







        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多