wiki.sine.space | sinespace

Difference between revisions of "Scripting/SNavMeshAgent"

From wiki.sine.space
Jump to: navigation, search
(Created page with "Navigation mesh agent. is attached to a mobile character in the game to allow it to navigate the Scene using the NavMesh. =Members= {{ScriptFunction|void|Move|(SVector mov...")
 
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/snavmeshagent")
 
(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>
+
&nbsp;&nbsp;&nbsp;&nbsp;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>
+
&nbsp;&nbsp;&nbsp;&nbsp;agent = Space.Scene.Find("Cube").AddNavMeshAgent()<br>
+
end<br>
+
counts = 0<br>
+
''--stop first, then resume.''<br>
+
function StopAndResume()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;counts = counts +1<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;if counts > 10 then<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;agent.Stop()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;if counts > 50 then<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;agent.Resume()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;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>
+
&nbsp;&nbsp;&nbsp;&nbsp;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>
+
&nbsp;&nbsp;&nbsp;&nbsp;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>
+
&nbsp;&nbsp;&nbsp;&nbsp;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>
+
&nbsp;&nbsp;&nbsp;&nbsp;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}}
+

Latest revision as of 06:10, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/snavmeshagent