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

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            91精品国产高清久久久久久91 | 久久久青草青青国产亚洲免观| 国内精品伊人久久久久| 久久久青草久久久青草| 97精品伊人久久久大香线蕉| 久久夜色精品国产亚洲av| 97精品依人久久久大香线蕉97| 99国产精品久久| 久久这里的只有是精品23| A狠狠久久蜜臀婷色中文网| 狠狠精品久久久无码中文字幕 | 国产精品久久毛片完整版| 久久精品免费大片国产大片 | 狠狠色丁香久久综合五月| 久久精品99无色码中文字幕| 久久久久AV综合网成人| 伊人色综合九久久天天蜜桃 | 看久久久久久a级毛片| 国产精品成人久久久久久久| 婷婷久久久亚洲欧洲日产国码AV| 久久久久久国产精品美女| 久久精品国产第一区二区三区| 欧美久久久久久| 99久久精品这里只有精品 | 日韩av无码久久精品免费| 久久91精品国产91久久户| 久久精品国产亚洲AV蜜臀色欲| 国产精品美女久久久久AV福利 | 久久夜色精品国产噜噜麻豆| 性高朝久久久久久久久久| 国产精品女同一区二区久久| 91久久婷婷国产综合精品青草| 99精品国产99久久久久久97| 看全色黄大色大片免费久久久 | 无码国产69精品久久久久网站| 2021久久精品免费观看| 无码任你躁久久久久久| 精品久久人人爽天天玩人人妻| 久久线看观看精品香蕉国产| 亚洲国产精品久久久久婷婷软件| 热久久国产精品|