• <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 閱讀(187) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            久久综合九色综合欧美狠狠| 久久天天躁狠狠躁夜夜2020一| 99re这里只有精品热久久| 国产成人久久久精品二区三区| 无码国内精品久久人妻麻豆按摩| 久久九九久精品国产免费直播| 999久久久免费精品国产| 欧美久久天天综合香蕉伊| 久久精品毛片免费观看| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 国产精品久久永久免费| 久久夜色撩人精品国产| 精品久久久久久亚洲| 亚洲精品无码久久千人斩| 久久强奷乱码老熟女| 久久久久国产精品| 久久久久AV综合网成人| 无码八A片人妻少妇久久| 久久综合综合久久狠狠狠97色88 | 亚洲香蕉网久久综合影视| 久久精品亚洲福利| 94久久国产乱子伦精品免费| 久久久久成人精品无码中文字幕 | 97香蕉久久夜色精品国产| 久久综合久久综合九色| 91久久婷婷国产综合精品青草| 婷婷伊人久久大香线蕉AV| 亚洲精品WWW久久久久久| 久久免费大片| 一本色道久久综合| 久久久午夜精品福利内容| 亚洲国产高清精品线久久| 亚洲色欲久久久久综合网| 久久99热这里只频精品6| 久久久久99这里有精品10| 亚洲午夜福利精品久久| 国产A三级久久精品| 久久久久亚洲AV无码永不| 2020久久精品国产免费| 91精品国产综合久久香蕉| 久久久久亚洲AV成人网|