青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

Controlling Players and Characters(10)

 

Controlling Non-Player Characters
 

As you’ve been able to surmise from the past few sections, controlling the player is
relatively simple. Now comes the tough part—controlling the game’s NPCs. This
section shows you the various methods of navigating your game’s NPCs.
 

Although games might trick you into thinking some elaborate scheme is moving
the NPCs around the world, that just isn’t the case.

Do you remember the five general types of NPC movements that I mentioned earlier—
standing still, wandering around an area, walking along a route, following a character,
and evading a character? With these in mind, you might want to take a closer look at
your favorite role-playing games to find out which control schemes they use.

As for your role-playing game, take a moment to examine the following controls
and how to implement them.

 

Standing Still
 

There’s not much to think about here—just place a character and he stands still
facing a specific direction. That direction is an angular rotation.

 

Wandering an Area
 

Games such as Ultima Online allow NPCs to wander around a set area, whether it is
the entire level or a section that you define. To keep things simple, you can specify
the range in which you want a character to wander, within a specific range of coordinates
(as illustrated in Figure 16.3).

These coordinates can be stored in variables such as these:

float WanderMinX, WanderMinY, WanderMinZ;
float WanderMaxX, WanderMaxY, WanderMaxZ;

Now, assuming that you are tracking a character’s coordinates in the level in a trio of
variables, you can move them around randomly and check whether a move is valid:

float CharXPos, CharYPos, CharZPos; // Character coordinates
float XMove, ZMove; // Movement amounts - skip YMove movements

// Distance to move character
float Distance;

// Determine a random direction to move - loop until found
while(1) {
  float Direction = 6.28f / 360.0f * (float)(rand() % 360);

  XMove = cos(Direction) * Distance;
  ZMove = sin(Direction) * Distance;

  // Check if move is valid - ignore height for now
  if(CharXPos+XMove >= WanderMinX && \
     CharXPos+XMove <= WanderMaxX && \
     CharZPos+ZMove >= WanderMinZ && \
     CharZPos+ZMove <= WanderMaxZ) {
       // Movement allowed, update coordinates
       CharXPos+=XMove;
       CharZPos+=ZMove;
       break; // break out of loop
  }
}

CAUTION
Don’t randomly move a character around at every frame, or you’ll find yourself with characters that look
like they’re having a conniption fit. Instead, update a character’s direction only every few seconds or so.

 

Walking a Route
 

Although NPCs aren’t intelligent enough to know their way around the level, you
can assign them routes to travel. These routes include coordinates that must be
reached in order to proceed to the next coordinates. Once the last set of coordinates
is reached, the character returns to the first set of coordinates and starts the
path all over again.

 

Using Route Points
 

Route points are defined as a set of coordinates, and keeping with the 3-D concept that
you’re accustomed to, you can use the following structure to store those coordinates:


typedef struct sRoutePoint {
   float XPos, ZPos;
} sRoutePoint;

NOTE
Note that there’s no need for a Y-coordinate when using a 3-D engine because the height is
determined by the height of the ground below the character.

In order to construct a route, you pick the points you want a character to walk and
construct an array of sRoutePoint structures to store the coordinates. Figure 16.4, for
example, shows a simple map, with five points marked.

Because each point in the route is marked with coordinates, you can see how to
construct the sRoutePoint structures array:

sRoutePoint Route[5] = {
  { -200.0f, -100.0f },
  { 100.0f, -300.0f },
  { 300.0f, -200.0f },
  { 200.0f, 100.0f },
  { 0.0f, 400.0f }
};

long NumRoutePoints = 5; // To make it easier to know # points

 

Walking from Point to Point
 

In order to proceed from point to point, a character walking a route needs to compare
its current coordinates to the point where it’s headed. You use this, combined
with the character’s walking speed, to compute a pair of movement variables that
update the character’s position.

Start by assuming that the character’s coordinates are kept in the following variables
(along with the character’s walking speed):


float CharXPos, CharZPos; // No Y-coordinate needed
float WalkSpeed; // Walking speed per frame
 

At this point, assume that you’ve already retrieved the coordinates you want the
character to walk to and placed them into another pair of variables:
 

float RouteXPos, RouteZPos; // Again, no Y-coordinate

Now, to start the character moving, you calculate the movement variables:

// Calculate distance from character to route point
float XDiff = (float)fabs(RouteXPos - CharXPos);
float ZDiff = (float)fabs(RouteZPos - CharZPos);
float Length = sqrt(XDiff*XDiff + ZDiff*ZDiff);

// Calculate movement towards point
float MoveX = (RouteXPos - CharXPos) / Length * WalkSpeed;
float MoveZ = (RouteZPos - CharZPos) / Length * WalkSpeed;

Whenever you update the character per frame from now on, you’ll need to add
MoveX and MoveZ to the character’s coordinates, as in the following:

CharXPos += MoveX;
CharZPos += MoveZ;

With that aside, go back and see just how to track which route point a character is
walking toward. When one route point is reached, the character must walk toward
the next. To determine when a route point is reached, you check the distance from
the character to the route point; if the distance is within a certain limit, the character
has reached the point and is allowed to continue on to the next route point.


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


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国内精品久久久久影院优| 亚洲一区精彩视频| 午夜精品亚洲| 亚洲午夜黄色| 亚洲永久网站| 久久精品国产久精国产一老狼| 亚洲欧美综合| 欧美在线观看视频在线| 久久永久免费| 亚洲国产婷婷| 99在线精品视频| 亚洲天堂男人| 久久精品一区二区| 欧美日本一区二区高清播放视频| 欧美视频在线看| 国产精品久久久久久久久久久久久久| 久久久久久欧美| 亚洲国产精品嫩草影院| 一区二区三区国产| 欧美一区视频| 欧美国产一区二区在线观看 | 亚洲欧美不卡| 老鸭窝毛片一区二区三区| 亚洲福利久久| 日韩亚洲在线观看| 久久久国产视频91| 欧美亚洲第一区| 亚洲欧洲日韩综合二区| 欧美一区二区三区免费观看| 免费成人毛片| 亚洲欧美激情视频在线观看一区二区三区| 久久国产精品久久久久久| 欧美日韩亚洲一区二| 黄色av日韩| 亚洲欧美视频| 日韩特黄影片| 免费成人av资源网| 国产麻豆日韩| 在线亚洲电影| 欧美激情在线| 久久精品国产99精品国产亚洲性色 | 欧美日韩大片一区二区三区| 国产午夜精品在线观看| 99视频日韩| 亚洲国产精品99久久久久久久久| 欧美一区1区三区3区公司| 欧美日韩一区二区在线观看视频 | 久久久国产一区二区三区| 国产精品ⅴa在线观看h| 一本久久综合亚洲鲁鲁五月天 | 亚洲午夜av| 欧美激情在线观看| 亚洲成色www久久网站| 久久国产精品久久久久久久久久| 亚洲亚洲精品三区日韩精品在线视频 | 亚洲国产精品va在看黑人| 久久国产88| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 欧美中文在线免费| 亚洲自拍偷拍视频| 亚洲欧洲三级| 麻豆精品国产91久久久久久| 亚洲一区二区三区中文字幕在线 | 国产人成一区二区三区影院| 亚洲免费视频成人| 日韩视频在线一区二区三区| 欧美日韩精选| 亚洲综合精品四区| 亚洲在线一区二区三区| 国产精品麻豆欧美日韩ww| 午夜精彩国产免费不卡不顿大片| 中文一区在线| 国模大胆一区二区三区| 久久亚洲美女| 欧美精品一区二区三区在线看午夜| 亚洲人成毛片在线播放| 日韩午夜在线| 国产精品一区二区你懂的| 久久久久久伊人| 欧美r片在线| 亚洲伊人观看| 欧美一级片在线播放| 亚洲国产另类久久久精品极度| 亚洲高清久久久| 欧美特黄a级高清免费大片a级| 欧美一区二区在线免费播放| 久久久久国产免费免费| 亚洲精品综合精品自拍| 亚洲在线视频网站| 亚洲第一色在线| 亚洲美女尤物影院| 国内精品久久久久影院色| 亚洲国产一区二区a毛片| 国产精品海角社区在线观看| 免费在线观看日韩欧美| 欧美视频二区| 久久综合中文色婷婷| 欧美日韩久久| 久久影视三级福利片| 欧美丝袜一区二区三区| 免费成人黄色| 国产精品一区二区三区四区 | 亚洲大胆av| 国产精品欧美一区二区三区奶水| 欧美.www| 国产日韩一区二区三区| 亚洲欧洲三级电影| 精品福利免费观看| 国产精品99久久久久久www| 在线日韩电影| 亚洲欧美日韩人成在线播放| 99精品欧美| 久久综合网络一区二区| 欧美一区二区三区四区夜夜大片| 欧美成年人网| 久久综合福利| 国产精品夜夜夜| 亚洲日产国产精品| 亚洲国产精品一区在线观看不卡| 亚洲女同在线| 亚洲欧美日韩精品久久| 欧美激情精品久久久六区热门 | 你懂的亚洲视频| 欧美中文在线观看| 欧美日韩日日夜夜| 欧美激情一二三区| 精品福利免费观看| 久久国产精品亚洲77777| 午夜精品久久久久影视| 欧美日韩精品二区第二页| 欧美激情久久久久| 亚洲成人原创| 久久亚洲一区二区三区四区| 久久久www成人免费无遮挡大片 | 一级日韩一区在线观看| 亚洲欧洲精品天堂一级 | 精品69视频一区二区三区| 亚洲一区二区高清| 香蕉成人伊视频在线观看| 欧美特黄一区| 亚洲一级二级| 久久国产精品99精品国产| 国产亚洲亚洲| 久久精品国产综合| 久久中文字幕导航| 亚洲欧洲精品一区二区| 欧美激情视频网站| 亚洲精品中文字幕女同| 亚洲一区二区av电影| 国产精品久久久久久影视| 亚洲午夜精品视频| 久久av二区| 在线免费高清一区二区三区| 噜噜噜91成人网| 亚洲国产成人av在线| 日韩一级免费观看| 国产精品www网站| 久久成人18免费观看| 欧美.www| 亚洲一本视频| 国产一区二区久久精品| 久久综合伊人77777尤物| 91久久精品国产91久久| 亚洲一区制服诱惑| 狠狠综合久久av一区二区小说 | 欧美二区在线看| 亚洲精品视频二区| 久久成年人视频| 亚洲激情视频| 国产精品午夜av在线| 久久精品电影| 99re6热只有精品免费观看| 欧美一区二区三区免费观看| 亚洲国产欧美日韩另类综合| 欧美精品一区二区三区久久久竹菊| 亚洲欧美日韩在线播放| 亚洲成人自拍视频| 久久福利电影| 亚洲视频一区在线观看| 国内精品**久久毛片app| 欧美国产欧美亚洲国产日韩mv天天看完整 | 国产伦一区二区三区色一情| 久久看片网站| 99香蕉国产精品偷在线观看| 久久综合九色| 亚洲欧美综合一区| 亚洲欧洲一区二区在线播放| 国产乱码精品一区二区三| 男人的天堂亚洲| 久久国产加勒比精品无码| 亚洲日本欧美| 欧美粗暴jizz性欧美20| 欧美一区二区黄色| 一区二区三区回区在观看免费视频 | 欧美一区二区久久久| 亚洲人屁股眼子交8| 久久综合久色欧美综合狠狠| 亚洲欧美日韩一区在线观看| 夜色激情一区二区| 亚洲国产精品久久久久秋霞蜜臀|