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

天行健 君子當自強而不息

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>
            久久精品人人做人人爽| 一区二区视频在线观看| 欧美成人中文| 国产午夜久久| 在线免费观看欧美| 亚洲精选视频免费看| 一区二区精品在线| 欧美一区二区精品久久911| 久久精品一区二区三区不卡牛牛| 久久99伊人| 欧美顶级大胆免费视频| 最新成人av网站| 日韩视频免费观看高清完整版| 一区二区三区欧美亚洲| 羞羞答答国产精品www一本| 久久人人97超碰国产公开结果| 麻豆久久婷婷| 国产精品九九| 亚洲福利视频在线| 亚洲性线免费观看视频成熟| 久久国产精品72免费观看| 欧美成人精品在线观看| av不卡在线观看| 久久久天天操| 国产精品网站在线播放| 亚洲激情另类| 久久久91精品国产| 99热精品在线观看| 久久久久久综合网天天| 国产精品激情电影| 亚洲开发第一视频在线播放| 久久精品99久久香蕉国产色戒| 亚洲国产成人精品久久| 性18欧美另类| 欧美日韩亚洲综合| 亚洲国产精品热久久| 欧美一区二区三区婷婷月色 | 狠狠久久婷婷| 亚洲砖区区免费| 亚洲国产精品999| 性欧美精品高清| 国产精品久久久久久久久免费桃花| 亚洲成人资源网| 久久精品日韩欧美| 亚洲视频免费在线| 欧美日韩一区在线播放| 亚洲精品日韩激情在线电影| 久久久久久婷| 午夜久久一区| 国产伦精品一区二区三区在线观看| 最新日韩在线| 欧美大香线蕉线伊人久久国产精品| 亚洲欧美伊人| 国产欧美日韩综合一区在线播放 | 亚洲欧美另类在线观看| 亚洲精品国产系列| 欧美成人一区二区在线| 欧美一区二区免费观在线| 欧美性猛交99久久久久99按摩| 亚洲精品久久久久久久久久久| 另类天堂av| 久久精品国产96久久久香蕉| 国产视频一区欧美| 久久国产精品99久久久久久老狼| 亚洲主播在线播放| 国产老肥熟一区二区三区| 亚洲欧美在线播放| 欧美一区二区视频网站| 黄色成人在线免费| 牛牛影视久久网| 免费日本视频一区| 一区二区三区久久网| 亚洲视频福利| 国产午夜精品理论片a级探花| 久久久久久九九九九| 久久天天躁狠狠躁夜夜爽蜜月| 亚洲电影免费观看高清完整版在线| 免费成人在线观看视频| 欧美成人精品三级在线观看| 亚洲性色视频| 久久精品成人欧美大片古装| 1024日韩| 一区二区三区国产盗摄| 国产性猛交xxxx免费看久久| 久久偷窥视频| 欧美精品免费在线观看| 羞羞答答国产精品www一本 | 99这里有精品| 国产伦精品一区| 免费成人你懂的| 欧美午夜视频网站| 欧美成人日本| 国产精品久久久久三级| 久久久免费精品视频| 欧美激情按摩| 久久琪琪电影院| 欧美日韩你懂的| 久久精品免费观看| 欧美日韩成人综合| 老鸭窝亚洲一区二区三区| 欧美激情亚洲另类| 久久精品午夜| 欧美日韩精品一区二区三区四区| 久久久青草婷婷精品综合日韩| 欧美精品激情在线| 美日韩丰满少妇在线观看| 国产精品入口尤物| 亚洲高清av| 国内免费精品永久在线视频| 亚洲精品美女在线观看| 在线看片欧美| 亚洲女ⅴideoshd黑人| av成人免费观看| 免费欧美日韩| 乱中年女人伦av一区二区| 国产精品毛片| 亚洲精品在线看| 欧美福利视频在线| 一区二区不卡在线视频 午夜欧美不卡在 | 黑人巨大精品欧美黑白配亚洲 | 亚洲精品综合| 亚洲国产精品黑人久久久 | 久久综合久久久| 久久精品一本久久99精品| 国产精品久久久久久av下载红粉 | 国产日韩欧美不卡在线| 亚洲最黄网站| 中文国产成人精品| 欧美激情一区二区三区蜜桃视频| 久久久亚洲一区| 国产一区二区三区久久久久久久久 | 久久福利视频导航| 午夜在线观看欧美| 国产精品h在线观看| 亚洲国产日韩欧美一区二区三区| 狠狠干综合网| 久久精品欧洲| 蜜臀99久久精品久久久久久软件| 一区二区三区在线视频播放| 久久精品日韩一区二区三区| 老司机精品久久| 亚洲国产精品成人综合色在线婷婷| 久久久亚洲一区| 亚洲第一在线综合在线| 最新国产の精品合集bt伙计| 欧美精品久久久久久| 亚洲欧洲日本专区| 一区二区三区视频观看| 欧美无乱码久久久免费午夜一区| 99国内精品| 欧美一级在线播放| 国内精品久久久久久影视8| 久久久久青草大香线综合精品| 久久久999国产| 亚洲国产专区校园欧美| 欧美日韩免费看| 亚洲欧美日韩精品一区二区| 久久人人97超碰国产公开结果| 一色屋精品视频在线看| 欧美精品aa| 午夜一级久久| 亚洲二区三区四区| 亚洲一区精品在线| 国产午夜亚洲精品不卡| 女女同性精品视频| 一区二区三区欧美在线| 久久www免费人成看片高清| 在线精品国产成人综合| 欧美日韩亚洲成人| 久久日韩精品| 亚洲一区中文| 亚洲国产婷婷香蕉久久久久久| 欧美无乱码久久久免费午夜一区| 亚洲欧美中文在线视频| 国产在线日韩| 欧美精品亚洲二区| 欧美一区成人| 亚洲另类一区二区| 久久久久久久综合色一本| 中文亚洲字幕| 亚洲国产1区| 国产午夜精品视频| 欧美日韩mv| 久久久久久久91| 亚洲午夜精品网| 亚洲国产成人高清精品| 久久精品国产999大香线蕉| 日韩图片一区| 精品999久久久| 国产精品视频福利| 欧美成年人网| 久久中文久久字幕| 久久se精品一区二区| 一本色道久久99精品综合| 欧美大胆成人| 欧美va天堂va视频va在线| 久久久久成人精品| 欧美在线视频全部完| 亚洲一区二区三区成人在线视频精品| 在线观看国产成人av片|