• <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游戲編程相關鏈接

            搜索

            最新評論

            久久久精品免费国产四虎| 天堂无码久久综合东京热| 久久久久免费精品国产| 久久久精品国产免大香伊| 亚洲中文字幕无码久久精品1| 99久久免费国产精品热| 精品无码人妻久久久久久| 久久久久久久久久久精品尤物| 久久久噜噜噜久久熟女AA片| 久久本道久久综合伊人| 久久成人国产精品| 思思久久99热只有频精品66| 国产精品女同久久久久电影院| 久久午夜福利电影| 国产精品久久久久…| 2021最新久久久视精品爱| 久久综合久久综合九色| 久久精品亚洲AV久久久无码| 国产精品99久久久久久猫咪 | 久久综合给合久久国产免费| 国产精品嫩草影院久久| 97久久精品人妻人人搡人人玩| 欧美成人免费观看久久| 久久久久99精品成人片三人毛片 | 激情久久久久久久久久| 久久精品人人做人人爽97| 久久无码AV一区二区三区| 久久精品国产99久久丝袜| 好久久免费视频高清| 日韩精品久久久久久免费| 久久精品国产清自在天天线| 久久久久无码专区亚洲av| 久久精品国产69国产精品亚洲| 久久久久人妻精品一区| 国产精品一久久香蕉国产线看观看| 久久免费看黄a级毛片| 久久精品国产99国产精品亚洲| 久久九九久精品国产| 久久伊人五月天论坛| 久久亚洲中文字幕精品一区四| 久久久久久av无码免费看大片|