天天看點

Unity NavMeshAgent參數及APINavMeshAgent

前言:Unity版本為2019.2.9f1 Ppersonal。Unity版本可在上方Help下點選About Unity找到。本文将采用官方文檔的英文并對比介紹。由于個人英文和開發水準有限,翻譯或解釋不到位的地方還請原諒。個别方法鑒于目前還沒使用過,不好做過多介紹,隻好先貼出來以供暫時了解即可。看完覺得有幫助還請點個贊,還想看其他文章的也請加個關注哦~喵。

文章目錄

  • NavMeshAgent
    • Properties
      • Insepecotr
          • Agent Type
          • Base Offset
        • Steering(操縱)
          • Speed(float)
          • Angular Speed(float)
          • Acceleration(float)
          • Stopping Distance(float)
          • Auto Braking(bool)
        • Obstacle Avoidance(障礙回避)
          • Radius(float)
          • Height(float)
          • Quality(enum)
          • priority(int)
        • Pathing Finding(尋路)
          • autoTraverseOffMeshLink(bool)
          • autoRepath(bool)
          • areaMask(int)
      • 非Inspector
          • avoidancePriority(int)
          • currentOffMeshLinkData(AI.OffMeshLinkData)
          • desiredVelocity(Vector3)
          • destination(Vector3)
          • hasPath(bool)
          • isOnNavMesh(bool)
          • isOnOffMeshLink(bool)
          • isPathStale(bool)
          • isStopped(bool)
          • navMeshOwner(Object)
          • nextOffMeshLinkData(AI.OffMeshLinkData)
          • nextPosition(Vector3)
          • obstacleAvoidanceType(AI.ObstacleAvoidanceType)
          • path(AI.NavMeshPath)
          • pathPending(bool)
          • pathStatus(AI.NavMeshPathStatus)
          • steeringTarget(Vector3)
          • updatePosition(bool)
          • updateRotation(bool)
          • updateUpAxis(bool)
          • velocity(Vector3)
    • API(Public Methods)
          • ActivateCurrentOffMeshLink(void)
          • CalculatePath(bool)
          • CompleteOffMeshLink(void)
          • FindClosestEdge(bool)
          • GetAreaCost(float)
          • Move(Vector3)
          • Raycast(bool)
          • ResetPath(void)
          • SamplePathPosition(bool)
          • SetAreaCost(void)
          • SetDestination(bool)
          • SetPath(bool)
          • Warp(bool)

NavMeshAgent

Properties

Insepecotr

This component is attached to a mobile character in the game to allow it to navigate the Scene using the NavMesh. See the Navigation section of the manual for further details.

該元件附加在遊戲中一個可移動的人物上,進而允許它使用NavMesh在Scene中導航。簡單地說,該元件提供了自動尋路的功能。

閱讀前須知:

我們将遊戲對象GameObject上挂載的NavMeshAgent元件稱為Agent。我們用代碼,通過對Agent進行調整來移動GameObject,是以通常來講Agent指代的就是遊戲對象。但Agent依然是一個元件,隻不過它控制着GameObject的運動而已。

我們将地圖上Agent可穿行的區域稱為NavMesh,即導航網格。

Unity NavMeshAgent參數及APINavMeshAgent
Agent Type

The type ID for the agent.

This identifier determines which NavMeshes are available for the Agent to move on. See also NavMeshBuildSettings.agentTypeID. Changing this ID will reset the Agent’s current path.

這個辨別符決定了Agent可以在哪些NavMeshes上移動。另請參見NavMeshBuildSettings.agentTypeID。改變Agent Type将重置Agent的目前路徑。

該設定在Navigation中,Navigation可在Windows下的AI中找到。打開後,就能見到如圖所示的Agent Type了。該值的設定相當于人物的分類,比如你可以建立一個Animal的Agent Type,然後設定其相關的屬性。這樣在尋路時就會表現出與Humanoid不同的特征。

Unity NavMeshAgent參數及APINavMeshAgent
Base Offset

The relative vertical displacement of the owning GameObject.

遊戲對象的垂直相對位移。即agent的Y軸偏移,正值往下,負值往上。

Steering(操縱)

Steering内的參數一般都不在Inspector界面調整它,而是在代碼中進行設定。

Speed(float)

Maximum movement speed when following a path.

An agent will typically need to speed up and slow down as it follows a path (eg, it will slow down to make a tight turn). The speed is often limited by the length of a path segment and the time taken to accelerate and brake, but the speed will not exceed the value set by this property even on a long, straight path.

尋路時的最大移動速度。設定該數值為0并不能使得agent立刻停下,具體見IsStopped。

Angular Speed(float)

Maximum turning speed in (deg/s) while following a path.

This is the maximum rate at which the agent can turn as it rounds the “corner” defined by a waypoint. The actual turning circle is also influenced by the speed of the agent on approach and also the maximum acceleration.

尋路時的最大轉向速度(最大角速度)。值越大,agent的轉向越迅速。

Acceleration(float)

The maximum acceleration of an agent as it follows a path, given in units / sec^2.

An agent does not follow precisely the line segments of the path calculated by the navigation system but rather uses the waypoints along the path as intermediate destinations. This value is the maximum amount by which the agent can accelerate while moving towards the next waypoint.

當agent尋路時的最大加速度。單純實體意義上的加速度,控制速度變化的快慢。

Stopping Distance(float)

Stop within this distance from the target position.

It is seldom possible to land exactly at the target point, so this property can be used to set an acceptable radius within which the agent should stop. A larger stopping distance will give the agent more room for manoeuvre at the end of the path and might avoid sudden braking, turning or other unconvincing AI behaviour.

制動距離。當agent與目标點的距離小于它時會自動停下來以免越過目标點。

Auto Braking(bool)

Should the agent brake automatically to avoid overshooting the destination point?

If the agent needs to land close to the destination point then it will typically need to brake to avoid overshooting or endless “orbiting” around the target zone. If this property is set to true, the agent will brake automatically as it nears the destination.

該屬性設定為true時,agent會在到達Stopping Distance時直接停下。否則會出現當agent速度太快沖過目标點時,會緩慢的回到目标點的現象。

Obstacle Avoidance(障礙回避)

這下面調節的都是agent空間參數。在Unity中,agent是一個圓柱形的範圍空間,所有的AI智能尋路都是基于agent的參數設定。它相當于是一個有着觸發器屬性(ISTrigger)的Collider,但并不是一個觸發器甚至是碰撞器。

Radius(float)

The avoidance radius for the agent.

This is the agent’s “personal space” within which obstacles and other agents should not pass.

agent的躲避半徑。相當于agent的私人空間,在這個半徑内其它障礙或agent無法穿過。

Height(float)

The height of the agent for purposes of passing under obstacles, etc.

agent的高度。低于該值的障礙agent都無法穿過。

Quality(enum)

設定品質。我也不知道這個有什麼用,設定成High Quality就好了。

priority(int)

優先級。低優先級的agent會給高優先級的agent讓路。

Pathing Finding(尋路)

autoTraverseOffMeshLink(bool)

Should the agent move across OffMeshLinks automatically?

Off-mesh links are used to connect disjoint regions of the NavMesh. Usually, a character should be able to pass through or traverse a link automatically, which will happen if this property is set to true. However, it can also be set to false in cases where special control over movement is needed.

分離網格連結指的是兩個不相交的導航網格之間的連結路徑(比如agent跳過去飛過去等非實地路徑)。關于這個的詳細内容可以參看這篇部落格【Unity】12.3 Off Mesh Link元件。簡單來說,該值設定為true的話,agent将可以通過分離網格連結。将其設定為false的話,就需要你手動的給場景中的物體添加Off Mesh Link元件,進而使得agent可以到達其上。

autoRepath(bool)

Should the agent attempt to acquire a new path if the existing path becomes invalid?

A new path calculation is also attempted acquired if the agent reaches the end of a partial and stale path.

該值預設為true,agent會在到達一條局部或過時的路徑末端時重新規劃一條路徑。如果你希望通過代碼來調控它的路徑選擇,你可以在Start中将其設定為false以免多次計算。

areaMask(int)

Specifies which NavMesh areas are passable. Changing areaMask will make the path stale (see isPathStale).

This is a bitfield.

該值指明哪些NavMesh是可通行的。

非Inspector

avoidancePriority(int)

The avoidance priority level.

When the agent is performing avoidance, agents of lower priority are ignored. The valid range is from 0 to 99 where: Most important = 0. Least important = 99. Default = 50.

回避優先級。當agent執行回避操作時會忽略掉低優先級的agents。0-99都是有效的範圍。其中,0是最高優先級,99最低,預設為50。

currentOffMeshLinkData(AI.OffMeshLinkData)

The current OffMeshLinkData.

In the case that this agent is not on an OffMeshLink the OffMeshLinkData is marked as invalid.

目前的分離網格連結資料。在某種情況下agent不在分離網格的連結上時,分離網格的連結資料會被标記為無效的。

desiredVelocity(Vector3)

The desired velocity of the agent including any potential contribution from avoidance. (Read Only)

agent的預期速度,其中包括任何來自障礙的潛在限制。是以它并不是一個定值。

destination(Vector3)

Gets or attempts to set the destination of the agent in world-space units.

Getting:

Returns the destination set for this agent.

  • If a destination is set but the path is not yet processed the position returned will be valid navmesh position that’s closest to the previously set position.
  • If the agent has no path or requested path - returns the agents position on the navmesh.
  • If the agent is not mapped to the navmesh (e.g. Scene has no navmesh) - returns a position at infinity.

Setting:

Requests the agent to move to the valid navmesh position that’s closest to the requested destination.

  • The path result may not become available until after a few frames. Use pathPending to query for outstanding results.
  • If it’s not possible to find a valid nearby navmesh position (e.g. Scene has no navmesh) no path is requested. Use SetDestination and check return value if you need to handle this case explicitly.
hasPath(bool)

Does the agent currently have a path? (Read Only)

This property will be true if the agent has a path calculated to the desired destination and false otherwise.

agent是否已經計算出了一條前往預定目的地的路徑。

isOnNavMesh(bool)

Is the agent currently bound to the navmesh? (Read Only)

This property is false if the agent, for some reason, could not bind to the navmesh. E.g. if Scene has no navmesh.

該值為true時表明agent在導航網格上。

isOnOffMeshLink(bool)

Is the agent currently positioned on an OffMeshLink? (Read Only)

This property is useful when autoTraverseOffMeshLink is false and custom movement is needed when crossing the link.

同上isOnNavMesh。

isPathStale(bool)

Is the current path stale. (Read Only)

When true, the path may no longer be valid or optimal. This flag will be set if: there are any changes to the areaMask, if any OffMeshLink is enabled or disabled, or if the costs for the NavMeshAreas have been changed.

該值為true表明路徑不再有效或者并不是最佳的。當areaMask被改變時,或任意一個分離網格連結被啟用或禁用時,或某一導航網格區域的代價被改變時,都會使得該值變為true。

isStopped(bool)

This property holds the stop or resume condition of the NavMesh agent.

If set to True, the NavMesh agent’s movement will be stopped along its current path. If set to False after the NavMesh agent has stopped, it will resume moving along its current path.

該屬性儲存agent的停止或恢複條件。

該值為true,agent的移動将沿着其目前路徑停止。 如果在agent尋路時将該屬性設定為false,它将會因為慣性繼續沿着它目前的尋路路徑移動一小段距離。

navMeshOwner(Object)

Returns the owning object of the NavMesh the agent is currently placed on (Read Only).

If no owner is set for a NavMesh or link instance the return value is null.

傳回agent目前所處導航網格的擁有者。如果該導航網格沒有擁有者,或者沒有連結執行個體,那麼它會傳回null。

nextOffMeshLinkData(AI.OffMeshLinkData)

The next OffMeshLinkData on the current path.

In the case that the current path does not contain an OffMeshLink the OffMeshLinkData is marked as invalid.

目前路徑的下一個OffMeshLinkData。在某種情況下,目前路徑并不包含一個分離網格連結,那麼下一個分離網格連結就會被标記為無效。

nextPosition(Vector3)

Gets or sets the simulation position of the navmesh agent.

The position vector is in world space coordinates and units.

The nextPosition is coupled to Transform.position. In the default case the navmesh agent’s Transform position will match the internal simulation position at the time the script Update function is called. This coupling can be turned on and off by setting updatePosition.

When updatePosition is true, the Transform.position reflects the simulated position, when false the position of the transform and the navmesh agent is not synchronized, and you’ll see a difference between the two in general. When updatePosition is turned back on, the Transform.position will be immediately move to match nextPosition.

By setting nextPosition you can directly control where the internal agent position should be. The agent will be moved towards the position, but is constrained by the navmesh connectivity and boundaries. As such it will be useful only if the positions are continuously updated and assessed.

擷取或設定導航網格代理的模拟位置。

位置向量采用的是空間坐标和機關。

nextPosition被耦合到了變換位置上。在預設情況下導航網格代理的變換位置會在腳本中的Update方法被調用時比對到局部的模拟位置。這種耦合可以通過設定updatePosition來打開或關閉。

當updatePosition為true時,變換位置映射出模拟的位置。反之變換位置和導航網格代理就是不同步的,如果你這麼設定就可以看到兩者在運動的過程中分離開來。當updatePosition被重新打開時,變換位置将會立即被移去比對nextPosition。

通過設定nextPosition,你可以直接控制局部的agent位置應該處于的地方。agent将會被移去指定的位置,但是會受到導航網格連接配接性和邊界的限制。是以它隻有在位置是不停地更新或評估時才有用。

obstacleAvoidanceType(AI.ObstacleAvoidanceType)

The level of quality of avoidance.

This property lets you trade off the precision of obstacle avoidance againt the processor load required to achieve it. The exact quality/performance values will depend heavily on the complexity of the Scene but as a general rule, faster performance can be achieved at the cost of quality and vice versa.

path(AI.NavMeshPath)

Property to get and set the current path.

This property can be useful for GUI, debugging and other purposes to get the points of the path calculated by the navigation system. Additionally, a path created from user code can be set for the agent to follow in the usual way. An example of this might be a patrol route designed for coverage rather than optimal distance between two points.

pathPending(bool)

Is a path in the process of being computed but not yet ready? (Read Only)

該值為true表明路徑正在計算中但還沒有準備好。

pathStatus(AI.NavMeshPathStatus)

The status of the current path (complete, partial or invalid).

目前路徑的狀态,比如是否完整、局部、無效的。

steeringTarget(Vector3)

Get the current steering target along the path. (Read Only)

This is typically the next corner along the path or the end point of the path.

Unless the agent is moving on an OffMeshLink, there is a straight path between the agent and the steeringTarget.

When approaching an OffMeshLink for traversal - the value is the position where the agent will enter the link. While agent is traversing an OffMeshLink the value is the position where the agent will leave the link.

updatePosition(bool)

Gets or sets whether the transform position is synchronized with the simulated agent position. The default value is true.

When true: changing the transform position will affect the simulated position and vice-versa.

When false: the simulated position will not be applied to the transform position and vice-versa.

Setting updatePosition to false can be used to enable explicit control of the transform position via script. This allows you to use the agent’s simulated position to drive another component, which in turn sets the transform position (eg. animation with root motion or physics).

When enabling the updatePosition (from previously being disabled), the transform will be moved to the simulated position. This way the agent stays constrained to the navmesh surface.

擷取或設定遊戲對象的變換位置是否與模拟的agent的位置同步,預設值是true。

如果為true,則改變對象的變換位置将會影響模拟的位置(agent的位置),反之亦然。

如果為false:模拟位置将不會應用于變換位置,反之亦然。

将updatePosition設定為false可用于通過腳本對變換位置啟用明确的控制。 這樣我們就可以使用agent的模拟位置來驅動另一個元件,進而設定變換位置(例如,具有根運動或實體特性的動畫)。

将updatePosition從禁用改為啟用時,變換位置将會被移去比對模拟位置。進而agent就被限制地在導航網格表面。

updateRotation(bool)

Should the agent update the transform orientation?

同updatePosition。

要注意的是,将updatePosition以及updateRotation設定為false的話,SetDestination就隻會使得agent去尋路,而遊戲對象會保持不動。由此我們可以知道,是agent的位置或旋轉帶動遊戲對戲的變換位置或旋轉。直接設定這兩個值并不會使得agent停下,隻是不讓它的位置和挂載對象的變換位置或旋轉同步而已。知道這個後,我們就可以在每一幀通過如下語句來使得物體到達目标點後立即停下。它的工作原理便是讓agent的位置或旋轉,在每一幀都強制等于遊戲對象的位置或旋轉上。

m_NavMeshAgent.updatePosition = false;
m_NavMeshAgent.updateRotation = false;
m_NavMeshAgent.nextPosition = transform.position;
           

另請參見nextPosition。

updateUpAxis(bool)

Allows you to specify whether the agent should be aligned to the up-axis of the NavMesh or link that it is placed on.

When this value is set to true, the agent will always be aligned to the local up-axis of the NavMesh or link that it is currently on. When set to false, the agent’s orientation is unaffected by the orientation of the NavMesh.

velocity(Vector3)

Access the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.

Reading the variable will return the current velocity of the agent based on the crowd simulation.

Setting the variable will override the simulation (including: moving towards destination, collision avoidance, and acceleration control) and command the NavMesh Agent to move using the specific velocity directly. When the agent is controlled using a velocity, its movement is still constrained on the NavMesh.

Setting the velocity directly, can be used for implementing player characters, which are moving on NavMesh and affecting the rest of the simulated crowd. In addition, setting priority to high (a small value is higher priority), will make other simulated agents to avoid the player controlled agent even more eagerly.

It is recommended to set the velocity each frame when controlling the agent manually, and if releasing the control to the simulation, set the velocity to zero. If agent’s velocity is set to some value and then stopped updating it, the simulation will pick up from there and the agent will slowly decelerate (assuming no destination is set).

Note that reading the velocity will always return value from the simulation. If you set the value, the effect will show up in the next update. Since the returned velocity comes from the simulation (including avoidance and collision handling), it can be different than the one you set.

The velocity is specified in distance units per second (same as physics), and represented in global coordinate system.

API(Public Methods)

ActivateCurrentOffMeshLink(void)

public void ActivateCurrentOffMeshLink(bool activated);

Parameters Description
actived Is the link activated?

Enables or disables the current off-mesh link.

This function activates or deactivates the off-mesh link where the agent is currently waiting. This is useful for granting access to newly discovered areas of the game world or simulating the creation or removal of an obstacle to an area.

啟用或禁用目前的分離網格連結。

該方法激活或停用agent目前正在等待的分離網格連結。這有助于授權agent對象通路遊戲世界的新發現的區域,或者模拟出對某個區域的障礙物的創造或移除。

總的來說,我也不知道這個方法有什麼用。

CalculatePath(bool)

public bool CalculatePath(Vector3 targetPosition, AI.NavMeshPath path);

Parameters Description
targetPosition The final position of the path requested.
path The resulting path.
Return bool True if a path is found.

Calculate a path to a specified point and store the resulting path.

This function can be used to plan a path ahead of time to avoid a delay in gameplay when the path is needed. Another use is to check if a target position is reachable before moving the agent.

CompleteOffMeshLink(void)

public void CompleteOffMeshLink();

Completes the movement on the current OffMeshLink.

The agent will move to the closest valid navmesh position on the other end of the current OffMeshLink.

CompleteOffMeshLink has no effect unless the agent is on an OffMeshLink (See Also: isOnOffMeshLink).

When autoTraverseOffMeshLink is disabled an agent will pause at an off-mesh link until this function is called. It is useful for implementing custom movement across OffMeshLinks.

FindClosestEdge(bool)

public bool FindClosestEdge(out AI.NavMeshHit hit);

Parameters Description
hit Holds the properties of the resulting location.
Return bool True if a nearest edge is found.

Locate the closest NavMesh edge.

The returned NavMeshHit object contains the position and details of the nearest point on the nearest edge of the Navmesh. Since an edge typically corresponds to a wall or other large object, this could be used to make a character take cover as close to the wall as possible.

GetAreaCost(float)

public float GetAreaCost(int areaIndex);

areaIndex Area Index.

Returns

float Current cost for specified area index.

Parameters Description
areaIndex Area Index.
Return float Current cost for specified area index.

Gets the cost for path calculation when crossing area of a particular type.

The cost of a path is the amount of “difficulty” involved in calculating it - the shortest path may not be the best if it passes over difficult ground, such as mud, snow, etc. Different types of areas are denoted by navmesh areas in Unity. The cost of a particular area is given in cost units per distance unit. Note that the cost of a path applies to the pathfinding only and does not automatically affect the movement speed of the agent when following the path. Indeed, the path’s cost may denote other factors such as danger (safe but long path through a minefield) or visibility (long path that keeps a character in the shadows).

Move(Vector3)

public void Move(Vector3 offset);

Parameters Description
offset The relative movement vector.

Apply relative movement to current position.

If the agent has a path it will be adjusted.

不常用的方法。直接給agent提供一個運動的方向,它會朝着這個方向一直運動。前提是它在導航網格上。如果agent正在尋路,那麼該方法會被打斷。

Raycast(bool)

public bool Raycast(Vector3 targetPosition, out AI.NavMeshHit hit);

Parameters Description
targetPosition The desired end position of movement.
hit Properties of the obstacle detected by the ray (if any).
Return bool True if there is an obstacle between the agent and the target position, otherwise false.

Trace a straight path towards a target postion in the NavMesh without moving the agent.

This function follows the path of a “ray” between the agent’s position and the specified target position. If an obstruction is encountered along the line then a true value is returned and the position and other details of the obstructing object are stored in the hit parameter. This can be used to check if there is a clear shot or line of sight between a character and a target object. This function is preferable to the similar Physics.Raycast because the line tracing is performed in a simpler way using the navmesh and has a lower processing overhead.

ResetPath(void)

public void ResetPath();

Clears the current path.

When the path is cleared, the agent will not start looking for a new path until SetDestination is called.

Note that if the agent is on an OffMeshLink when this function is called, it will complete the link immediately.

清除目前路徑。

路徑被清除後,agent不會再次尋找新的路徑,直到SetDestination方法被調用。有一點需要注意,當agent正在一個分離網格連結上時(比如正在從一個建築物跳到另一個建築物的過程中)調用該方法,它會立即完成這一連結動作(表現出來就是立刻閃爍到另一個建築物上)。

還需要注意的是,清除路徑并不意味着使agent停下,隻是不再尋找新的路徑而已。

SamplePathPosition(bool)

public bool SamplePathPosition(int areaMask, float maxDistance, out AI.NavMeshHit hit);

Parameters Description
areaMask A bitfield mask specifying which NavMesh areas can be passed when tracing the path.
maxDistance Terminate scanning the path at this distance.
hit Holds the properties of the resulting location.
Return bool True if terminated before reaching the position at maxDistance, false otherwise.

Sample a position along the current path.

This function looks ahead a specified distance along the current path. Details of the mesh at that position are then returned in a NavMeshHit object. This could be used, for example, to check the type of surface that lies ahead before the character gets there - a character could raise his gun above his head if he is about to wade through water, say.

沿着目前路徑取樣一個坐标。

該方法會沿着目前路徑檢查指定的距離,如果取樣到某一層上的點,會在NavMeshHit對象中傳回該點網格的詳細資訊。 舉個例子,這可以用于檢查在角色到達目标點之前,前方是否存在某一物體。例如,如果角色打算涉水而過,它可以将槍舉過頭頂。那麼這個方法就可以檢測前方是否有水。

SetAreaCost(void)

public void SetAreaCost(int areaIndex, float areaCost);

Parameters Description
areaIndex Area cost.
areaCost New cost for the specified area index.

Sets the cost for traversing over areas of the area type.

If you enable or disable the agent then the cost will be reset to the default layer cost.

設定穿過某一特定類型區域的代價。

如果你啟用或禁用了agent,這個代價将會被重置為預設的層級代價。

SetDestination(bool)

public bool SetDestination(Vector3 target);

Parameters Description
target The target point to navigate to.
Return bool True if the destination was requested successfully, otherwise false.

Sets or updates the destination thus triggering the calculation for a new path.

Note that the path may not become available until after a few frames later. While the path is being computed, pathPending will be true. If a valid path becomes available then the agent will resume movement.

設定或更新目的地進而觸發新路徑的計算。

這是最常用的方法,設定一個目的地然後讓agent自動尋路。要注意的是,新計算出的路徑在過幾幀之後才有用。在路徑被計算時,pathPending的值是true。在一個有效的路徑變得可用後,agent會恢複移動。

這一點是需要注意的。新計算出的路徑并不會使得agent直接去尋路,而是要經過幾幀才會執行。是以最好是在找到路徑過一會兒後再讓agent去尋路。

SetPath(bool)

public bool SetPath(AI.NavMeshPath path);

Parameters Description
path New path to follow.
Return bool True if the path is succesfully assigned.

Assign a new path to this agent.

If the path is succesfully assigned the agent will resume movement toward the new target. If the path cannot be assigned the path will be cleared (see ResetPath).

為agent配置設定一個新的路徑。

該方法強制使agent走配置設定的路徑。如果路徑被成功配置設定之後,agent會恢複前往新目标的移動。如果路徑不能被配置設定,那麼它會被清除掉。

Warp(bool)

public bool Warp(Vector3 newPosition);

Parameters Description
newPosition New position to warp the agent to.
Return bool True if agent is successfully warped, otherwise false.

Warps agent to the provided position.

Returns true if successful, otherwise returns false.

将agent直接放到提供的坐标處,可用于agent的瞬移。

1w7k字,好累啊嘤嘤嘤,帥氣gg漂亮mm麻煩點個贊麼麼哒~~~

繼續閱讀