14
Dept. of Electronics Engineering Construct 2 Pathfinding behavior 電子工程系電腦遊戲設計組 吳錫修 2014.3.9

Construct2 Pathfinding behavior

Embed Size (px)

DESCRIPTION

Pathfinding行為可讓物件自動在不同地形區域及有障礙物的空間中尋找短路徑,並向目標點移動。

Citation preview

Page 1: Construct2 Pathfinding behavior

Dept. of Electronics Engineering

Construct 2 Pathfindingbehavior

電子工程系電腦遊戲設計組

吳錫修

2014.3.9

Page 2: Construct2 Pathfinding behavior

Pathfinding行為 1/2

Pathfinding賦予物件路徑規劃能力,使用A *演算法有效地找出繞過障礙物的短路徑

Wu, ShyiShiou2

Page 3: Construct2 Pathfinding behavior

Pathfinding行為 2/2

Pathfinding可以輸出路徑的節點列表,或自動讓物件沿著所確定的路徑移動

Wu, ShyiShiou3

Page 4: Construct2 Pathfinding behavior

Pathfinding grid

以像素為計算單位可以找出精確路徑,但運算極為耗時;因此pathfinding是將場景分割成網格方式進行尋路運算

網格 ( cell size) 設定太大,可能造成原先可通過的小空隙被封閉

⼀般情況下,盡量使用不會造成障礙物四週錯誤導航的最大網格尺寸

Wu, ShyiShiou4

Page 5: Construct2 Pathfinding behavior

網格邊界

當Cell border設定值大於0,則那些接近障礙物的網格 (但沒有實際接觸) 也會被標示為障礙物,會擴展障礙區範圍

如果Cell border為負值,則部份剛剛觸及障礙物的網格可能不會被標記為障礙物,會使障礙區向內收縮

同⼀場景中的物件最好使用相同的cell size及cell border,否則系統必須在記憶體中建立不同的障礙物網格地圖

Wu, ShyiShiou5

Page 6: Construct2 Pathfinding behavior

Pathfinding properties 1/2

用來調整pathfinding行為參數

Cell size網格尺寸,單位pixels

Cell border網格邊框尺寸,單位pixels

Obstacles障礙物辨識方式。設定為Solid時,系統會自動將具備Solid行為的物件標示為障礙物。設定為Custom時,則必須在啟動時,透過Add obstacle定義那些物件要標示為障礙物

Max speed物件沿著路徑移動時的最大速度,單位pixels/second

Wu, ShyiShiou6

Page 7: Construct2 Pathfinding behavior

使用Pathfinding 2/2

Acceleration物件沿著路徑移動時的加速度,單位pixels/second

Deceleration物件沿著路徑移動接近最後節點時的減速度,單位pixels/second

Rotate speed物件沿著路徑移動時的轉彎速度,單位degrees/second。當轉彎速度設定值較低時,物件在急轉彎處會減速

Rotate object當物件沿著路徑移動時,是否自動調整物件移動角度

Diagonals是否允許沿對角線移動。禁用時,路徑會以直角方式轉彎

Initial state是否在⼀開始就啟用pathfinding功能 Wu, ShyiShiou7

Page 8: Construct2 Pathfinding behavior

Pathfinding conditions 1/2

提供給事件表的事件條件

Compare speed物件沿著路徑移動時,比較物件目前速度 (單位pixels/second)

Diagonals are enabled檢查是否已啟用對角線移動方式

Is calculating path是否正在計算路徑中

Is cell obstacle檢查格⼦是否被標記為⼀個障礙物。在調試或顯示障礙物網格時相當有用。注意,此事件Cell X與Cell Y參數指的是格⼦在障礙物網格資料中的位置不是場景坐標

Wu, ShyiShiou8

Page 9: Construct2 Pathfinding behavior

使用Pathfinding 2/2

Is moving along path目前是否正沿著路徑移動中

On arrived物件抵達路徑的最後節點

On failed to find path計算路徑結果無法找到移動路徑,例如目的地被障礙物環繞

On path found順利找到可移動路徑,此時就可使用NodeCount、NodeXAt及NodeYAt資料,並可對物件下達 "Move along path" 動作

Wu, ShyiShiou9

Page 10: Construct2 Pathfinding behavior

Pathfinding actions 1/4

事件表中可用的actions

Add obstacle當pathfinding物件的Obstacles屬性設定為Custom,可透過Add obstacl將指定物件設定為障礙物。如果是在遊戲進行中 (在Start of layout事件後) 才作業,則還必須執行Regenerate obstacle map動作來重新生成障礙地圖

Add path cost設定通過物件的路徑成本,用來模擬穿越崎嶇地形需要較多的路徑成本, 以便pathfinding計算穿越物件與繞過物件所耗的路徑成本。如果是在遊戲進行中 (在Start of layout事件後) 才作業,則還必須執行Regenerate obstacle map動作來重新生成障礙地圖

Wu, ShyiShiou10

Page 11: Construct2 Pathfinding behavior

Pathfinding actions 2/4

Clear cost清除所有Add path cost設定。注意,還必須執行Regenerate obstacle map動作來重新生成障礙地圖

Clear obstacles清除所有Add obstacle設定。注意,還必須執行Regenerate obstacle map動作來重新生成障礙地圖

Find path開始計算到目的點的路徑

Regenerate obstacle map重新生成障礙地圖

Set enabled禁用/啟用pathfinding

Wu, ShyiShiou11

Page 12: Construct2 Pathfinding behavior

Pathfinding actions 3/4

Move along path使pathfinding物件開始沿著路徑移動,注意,只能在On path found事件後使用

Set speed設定pathfinding物件目前速度,設定值不能為負值或超過Maxi speed屬性值

Stop使pathfinding物件停止移動

Set acceleration設定pathfinding物件加速度

Set deceleration設定pathfinding物件減速度

Wu, ShyiShiou12

Page 13: Construct2 Pathfinding behavior

Pathfinding actions 4/4

Set diagonals enabled啟用/禁用pathfinding物件對角線移動

Set max speed設定pathfinding物件最大速度

Set rotate speed設定pathfinding物件轉彎速度

Wu, ShyiShiou13

Page 14: Construct2 Pathfinding behavior

Pathfinding expressions

物件實體在Runtime時的pathfinding行為資料

CurrentNode目前移動路徑的下⼀個節點編號

MovingAngle目前沿著路徑的移動角度

NodeCount移動路徑中的節點總數

NodeXAt路徑中指定編號節點在場景中的X座標值

NodeYAt路徑中指定編號節點在場景中的Y座標值

Wu, ShyiShiou14