• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            Controlling Players and Characters(12)

             

            Following Another Character
             

            Although following another character might seem complicated at first, don’t worry
            too much. Remember that keeping it simple is the solution. Following a character
            is as easy as walking a route. Because a character already knows its own coordinates
            and the coordinates of the character it is following, you can use previously seen
            functions to move the character toward another one.
             

            The only difference at this point is that you might want a character to get within a
            specific distance from the followed character, as illustrated in Figure 16.5.

            Knowing each character’s coordinates (the character being followed and the character
            doing the following), you can construct a single function that determines
            which direction the “following” character should move:

            void CalculateFollowMovement(
              float CharXPos, float CharZPos, // Coordinate of character
              float WalkSpeed, // Walking speed of char.
              float FollowXPos, float FollowZPos, // Coords of followed char.
              float FollowDistance, // Distance to follow at
              float *MoveX, float *MoveZ) // Variables for movement
            {
              // Fix for faster distance checking
              FollowDistance *= FollowDistance;

              // Get distance between characters
              float XDiff = (float)fabs(FollowXPos - CharXPos);
              float ZDiff = (float)fabs(FollowZPos - CharZPos);
              float Length = XDiff*XDiff + ZDiff*ZDiff;

              // If distance between characters is less than allowed,
              // then just stand still.
              if(Length < FollowDistance) {
                *MoveX = *MoveZ = 0.0f;
                return;
              }

              // Calculate rate to move based on character walking speed
              Length = sqrt(Length);
              *MoveX = (CharXPos - FollowXPos) / Length * WalkSpeed;
              *MoveZ = (CharZPos - FollowZPos) / Length * WalkSpeed;
            }

            Whenever you want to update a character that is following another one, you merely
            pass along the required data and move the character using the returned movement
            variables.

             

            Evading Another Character
             

            Evading means to move a character away from another one. If the character to be
            avoided is closer than the minimum set distance, the evading character moves in
            the opposite direction through the use of the CalculateEvadeMovement function:

            void CalculateEvadeMovement(
              float CharXPos, float CharZPos, // Coordinate of character
              float WalkSpeed, // Walking speed of char.
              float FollowXPos, float FollowZPos, // Coords of evaded char.
              float EvadeDistance, // Distance to evade
              float *MoveX, float *MoveZ) // Variables for movement
            {
              // Fix for faster distance checking
              FollowDistance *= FollowDistance;

              // Get distance between characters
              float XDiff = (float)fabs(FollowXPos - CharXPos);
              float ZDiff = (float)fabs(FollowZPos - CharZPos);
              float Length = XDiff*XDiff + ZDiff*ZDiff;

              // If distance between characters is more than allowed,
              // then just stand still.
              if(Length > EvadeDistance) {
                *MoveX = *MoveZ = 0.0f;
                return;
              }

              // Calculate rate to move based on character walking speed
              Length = sqrt(Length);
              *MoveX = -((CharXPos - FollowXPos) / Length * WalkSpeed);
              *MoveZ = -((CharZPos - FollowZPos) / Length * WalkSpeed);
            }


            posted on 2007-11-14 15:56 lovedday 閱讀(185) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            热re99久久精品国99热| 99麻豆久久久国产精品免费| 国产产无码乱码精品久久鸭 | 久久SE精品一区二区| 中文字幕人妻色偷偷久久| 99久久精品午夜一区二区| 国产 亚洲 欧美 另类 久久| 国产免费福利体检区久久| 国产精品美女久久福利网站| 俺来也俺去啦久久综合网| 国产午夜精品理论片久久| 亚洲乱码精品久久久久..| 久久天天躁狠狠躁夜夜2020| 亚洲国产另类久久久精品小说| 99久久综合国产精品二区| 久久久精品人妻一区二区三区蜜桃| 狠狠狠色丁香婷婷综合久久五月| 亚洲精品高清一二区久久| 99久久精品国产一区二区蜜芽| 热久久视久久精品18| 国内精品久久久久久久涩爱 | 精品国产青草久久久久福利| 久久久久亚洲精品日久生情 | 久久99国产精品尤物| 亚洲性久久久影院| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久97久久97精品免视看秋霞| 久久久久人妻一区精品色| 亚洲午夜久久久| 久久伊人五月丁香狠狠色| 久久WWW免费人成—看片| 久久久久久久综合日本亚洲| 久久精品中文无码资源站| 久久久久无码精品国产| 无码超乳爆乳中文字幕久久 | 久久美女人爽女人爽| 久久久久久亚洲精品成人| 亚洲中文字幕无码久久精品1| 亚洲欧洲久久久精品| 尹人香蕉久久99天天拍| 久久精品国产亚洲av麻豆图片|