wiki.sine.space | sinespace

Difference between revisions of "Scripting/SNavMeshAgent"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/snavmeshagent")
 
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.''
+
}}
+
 
+
=Properties=
+
{{ScriptFunction|bool|Enabled|{get; set;}|Enable or disable this component.|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.Enabled = false<br>
+
'' --disable navmesh agent.''|6=<pre>--clicking this object will Enable/Disable it's Nav Mesh Agent component
+
thisGameObject = Space.Host.ExecutingObject
+
component = thisGameObject.NavMeshAgent
+
 
+
OnClick = function()
+
component.Enabled =  not component.Enabled
+
end
+
 
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|float|Accelleration|{get; set;}|The maximum acceleration of an agent as it follows a path.|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.Accelleration = 60<br>
+
'' --set accellratioon to 60.''
+
}}
+
 
+
{{ScriptFunction|float|Accelleration|{get; set;}|The maximum acceleration of an agent as it follows a path.|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.Accelleration = 60<br>
+
'' --set accellratioon to 60.''
+
}}
+
 
+
{{ScriptFunction|float|AngularSpeed|{get; set;}|Maximum turning speed in while following a path.|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.AngularSpeed = 60<br>
+
'' --set AngularSpeed to 60.''
+
}}
+
 
+
{{ScriptFunction|int|AreaMask|{get; set;}| Specifies which NavMesh area is passable.|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.AreaMask = 3<br>
+
''  --set AreaMask to layer1 and layer2.''
+
}}
+
 
+
{{ScriptFunction|bool|AutoRepath|{get; set;}| Set the agent attempt to acquire a new path if the existing path becomes invalid.|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.AutoRepath = false<br>
+
''--set AutoRepath false.''
+
}}
+
 
+
{{ScriptFunction|bool|AutoBraking|{get; set;}| Set the agent brake automatically to avoid overshooting the destination point.|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.AutoBraking = false<br>
+
''--set AutoBraking false.''
+
}}
+
 
+
{{ScriptFunction|bool|AutoTraverseOffMeshLink|{get; set;}| Set the agent move across OffMeshLinks automatically.|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.AutoTraverseOffMeshLink = false<br>
+
''--set AutoTraverseOffMeshLink false.''
+
}}
+
 
+
{{ScriptFunction|int|AvoidancePriority|{get; set;}|The avoidance priority level.|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.AvoidancePriority = 60<br>
+
''--set AvoidancePriority to 60.''
+
}}
+
 
+
{{ScriptFunction|float|BaseOffset|{get; set;}|The relative vertical displacement of the GameObject.|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.BaseOffset = 3<br>
+
''--set BaseOffset to 3.''
+
}}
+
 
+
{{ScriptFunction|SVector|DesiredVelocity|{get;}| The desired velocity of the agent including any potential contribution from avoidance.|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>
+
Space.Log(agent.DesiredVelocity.ToString())<br>
+
''--output the desired velocity.''
+
}}
+
 
+
{{ScriptFunction|SVector|Destination|{get; set;}| The desired velocity of the agent including any potential contribution from avoidance.|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 for target transforming.''
+
}}
+
 
+
{{ScriptFunction|bool|HasPath|{get;}|Does the agent currently have a path?|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>
+
Space.Log(agent.HasPath)<br>
+
''--Return has path or not.''
+
}}
+
 
+
{{ScriptFunction|float|Height|{get; set;}|The height of the agent for purposes of passing under obstacles, etc.|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.Height = 60<br>
+
'' --set height to 60.''
+
}}
+
 
+
 
+
{{ScriptFunction|bool|IsOnNavMesh|{get;}|Is the agent currently bound to the navmesh?|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>
+
Space.Log(agent.IsOnNavMesh)<br>
+
''--output this agent is on the navmesh.''
+
}}
+
 
+
{{ScriptFunction|bool|IsOnOffMeshLink|{get;}| Is the agent currently positioned on an OffMeshLink?|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>
+
Space.Log(agent.IsOnOffMeshLink)<br>
+
''--output this agent is on off meshlink.''
+
}}
+
 
+
{{ScriptFunction|bool|IsPathStale|{get;}|Is the current path stale?|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>
+
Space.Log(agent.IsPathStale)<br>
+
''--output the path is stale.''
+
}}
+
 
+
{{ScriptFunction|SVector|NextPosition|{get; set;}|Get or set the simulation position of 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>
+
function OutputNextPosition()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(agent.NextPosition)<br>
+
end<br>
+
agentobject.SubscribeToEvents()<br>
+
agentobject.OnUpdate(OutputNextPosition)<br>
+
''--register update events to navmesh agent's game object''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{ScriptFunction|SVector|PathEndPosition|{get;}|End positon of navigation.|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>
+
Space.Log(agent.PatchEndPosition)<br>
+
''--output the end position of the navmesh agent.''
+
}}
+
 
+
 
+
{{ScriptFunction|bool|PathPending|{get;}|Is a path in the process of being computed but not yet ready?|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>
+
function OutputPathPending()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(agent.PathPending)<br>
+
end<br>
+
agentobject.SubscribeToEvents()<br>
+
agentobject.OnUpdate(OutputPathPending)<br>
+
''--register update events to navmesh agent's game object''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{ScriptFunction|float|Radius|{get; set;}|The avoidance radius for the 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.Radius = 5<br>
+
''--set radius of agent to 5.''
+
}}
+
 
+
{{ScriptFunction|float|RemainingDistance|{get;}|The distance between the agent's position and the destination on the current path.|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>
+
function OutputRemainingDistance()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(agent.RemainingDistance)<br>
+
end<br>
+
agentobject.SubscribeToEvents()<br>
+
agentobject.OnUpdate(OutputRemainingDistance)<br>
+
''--register update events to navmesh agent's game object''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{ScriptFunction|float|Speed|{get; set;}|Maximum movement speed when following a path.|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.Speed = 20<br>
+
''--set speed to 20.''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{ScriptFunction|SVector|SteeringTarget|{get;}|Get the current steering target along the path.|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>
+
Space.Log(agent.SteeringTarget.ToString())<br>
+
''--output steering target position.''
+
}}
+
 
+
{{ScriptFunction|float|StoppingDistance|{get; set;}|Stop within this distance from the target 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.StoppingDistance = 2<br>
+
''--set stopping distance.''
+
}}
+
 
+
{{ScriptFunction|bool|UpdatePosition|{get; set;}Get or set whether the transform position is synchronized with the simulated agent 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.UpdatePosition = false<br>
+
''--set update position to false.''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{ScriptFunction|bool|UpdatePosition|{get; set;}Should the agent update the transform orientation?|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.UpdateRotation = false<br>
+
''--set update Rotation to false.''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{ScriptFunction|SVector|Velocity|{get;}|access the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.|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>
+
function OutputVelocity()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log("Velocity is : " .. agent.Velocity.ToString())<br>
+
end<br>
+
agentobject.SubscribeToEvents()<br>
+
agentobject.OnUpdate(OutputRemainingDistance)<br>
+
''--register update events to navmesh agent's game object''<br>
+
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition<br>
+
''--set destination.''
+
}}
+
 
+
{{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