|
|
(2 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
− | Navigation mesh agent. is attached to a mobile character in the game to allow it to navigate the Scene using the NavMesh.
| + | This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/snavmeshagent |
− | | + | |
− | | + | |
− | =Members=
| + | |
− | | + | |
− | | + | |
− | {{ScriptFunction|void|Move|(SVector movement);|Apply relative movement to current position.|5=agentobject = Space.Scene.Find("Cube")<br>
| + | |
− | agent = agentobject.NavMeshAgent<br>
| + | |
− | if agent == nil then<br>
| + | |
− | agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
| + | |
− | end<br>
| + | |
− | agent.Move(Vector.New(2,0,0))<br>
| + | |
− | ''--move forward 2 meters.''
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|void|Resume|();|Resume the NavMesh agent.|5=agentobject = Space.Scene.Find("Cube")<br>
| + | |
− | agent = agentobject.NavMeshAgent<br>
| + | |
− | if agent == nil then<br>
| + | |
− | agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
| + | |
− | end<br>
| + | |
− | counts = 0<br>
| + | |
− | ''--stop first, then resume.''<br>
| + | |
− | function StopAndResume()<br>
| + | |
− | counts = counts +1<br>
| + | |
− | if counts > 10 then<br>
| + | |
− | agent.Stop()<br>
| + | |
− | end<br>
| + | |
− | if counts > 50 then<br>
| + | |
− | agent.Resume()<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | agentobject.SubscribeToEvents()<br>
| + | |
− | agentobject.OnUpdate(StopAndResume)<br>
| + | |
− | agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
| + | |
− | ''--set destination.''
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|void|SetAreaCost|(int areaIndex, float cost);|Sets the cost for traversing over areas of the area type.|5=agentobject = Space.Scene.Find("Cube")<br>
| + | |
− | agent = agentobject.NavMeshAgent<br>
| + | |
− | if agent == nil then<br>
| + | |
− | agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
| + | |
− | end<br>
| + | |
− | agent.SetAreaCost(2,20)<br>
| + | |
− | ''--set area 2 cost to 20.''
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|void|Stop|();|To stop the NavMesh agent.|5=agentobject = Space.Scene.Find("Cube")<br>
| + | |
− | agent = agentobject.NavMeshAgent<br>
| + | |
− | if agent == nil then<br>
| + | |
− | agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
| + | |
− | end<br>
| + | |
− | agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
| + | |
− | '' --set destination.''<br>
| + | |
− | agent.Stop()<br>
| + | |
− | '' --stop the agent.''<br>
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|void|SetDestination|(SVector position);|Set or update the destination.|5=agentobject = Space.Scene.Find("Cube")<br>
| + | |
− | agent = agentobject.NavMeshAgent<br>
| + | |
− | if agent == nil then<br>
| + | |
− | agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
| + | |
− | end<br>
| + | |
− | agent.SetDestination(Space.Scene.Find("TargetTransform").WorldPosition)<br>
| + | |
− | '' --set destination.''
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|void|Wrap|(SVector position);|Wrap to the position you want, also you can set agent's world position and vector to make this act as Move(SVector position).|5=agentobject = Space.Scene.Find("Cube")<br>
| + | |
− | agent = agentobject.NavMeshAgent<br>
| + | |
− | if agent == nil then<br>
| + | |
− | agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
| + | |
− | end<br>
| + | |
− | agent.Wrap(Vector.New(2,0,0)+agent.GameObject.WorldPosition)<br>
| + | |
− | '' --Wrap forward 2 meters.''
| + | |
− | }}
| + | |
− | | + | |
− | {{Scripting Navbox}}
| + | |