wiki.sine.space | sinespace

Scripting/SNavMeshAgent

From wiki.sine.space
Revision as of 03:53, 13 October 2021 by Voidtech (Talk | contribs)

Jump to: navigation, search

Navigation mesh agent. is attached to a mobile character in the game to allow it to navigate the Scene using the NavMesh.


Members

Move

void Move (SVector movement);

Apply relative movement to current position.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Move(Vector.New(2,0,0))

--move forward 2 meters.


Resume

void Resume ();

Resume the NavMesh agent.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
counts = 0
--stop first, then resume.
function StopAndResume()
    counts = counts +1
    if counts > 10 then
      agent.Stop()
    end
    if counts > 50 then
      agent.Resume()
    end
end
agentobject.SubscribeToEvents()
agentobject.OnUpdate(StopAndResume)
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


SetAreaCost

void SetAreaCost (int areaIndex, float cost);

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

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.SetAreaCost(2,20)

--set area 2 cost to 20.


Stop

void Stop ();

To stop the NavMesh agent.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
--set destination.
agent.Stop()

--stop the agent.


SetDestination

void SetDestination (SVector position);

Set or update the destination.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.SetDestination(Space.Scene.Find("TargetTransform").WorldPosition)

--set destination.


Wrap

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).

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Wrap(Vector.New(2,0,0)+agent.GameObject.WorldPosition)

--Wrap forward 2 meters.


Properties

Enabled

bool Enabled {get; set;}

Enable or disable this component.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Enabled = false

--disable navmesh agent.


--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)

Accelleration

float Accelleration {get; set;}

The maximum acceleration of an agent as it follows a path.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Accelleration = 60

--set accellratioon to 60.


Accelleration

float Accelleration {get; set;}

The maximum acceleration of an agent as it follows a path.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Accelleration = 60

--set accellratioon to 60.


AngularSpeed

float AngularSpeed {get; set;}

Maximum turning speed in while following a path.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.AngularSpeed = 60

--set AngularSpeed to 60.


AreaMask

int AreaMask {get; set;}
Specifies which NavMesh area is passable.
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.AreaMask = 3

--set AreaMask to layer1 and layer2.


AutoRepath

bool AutoRepath {get; set;}
Set the agent attempt to acquire a new path if the existing path becomes invalid.
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.AutoRepath = false

--set AutoRepath false.


AutoBraking

bool AutoBraking {get; set;}
Set the agent brake automatically to avoid overshooting the destination point.
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.AutoBraking = false

--set AutoBraking false.


AutoTraverseOffMeshLink

bool AutoTraverseOffMeshLink {get; set;}
Set the agent move across OffMeshLinks automatically.
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.AutoTraverseOffMeshLink = false

--set AutoTraverseOffMeshLink false.


AvoidancePriority

int AvoidancePriority {get; set;}

The avoidance priority level.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.AvoidancePriority = 60

--set AvoidancePriority to 60.


BaseOffset

float BaseOffset {get; set;}

The relative vertical displacement of the GameObject.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.BaseOffset = 3

--set BaseOffset to 3.


DesiredVelocity

SVector DesiredVelocity {get;}
The desired velocity of the agent including any potential contribution from avoidance.
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
Space.Log(agent.DesiredVelocity.ToString())

--output the desired velocity.


Destination

SVector Destination {get; set;}
The desired velocity of the agent including any potential contribution from avoidance.
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end

agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
--set destination for target transforming.


HasPath

bool HasPath {get;}

Does the agent currently have a path?

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
Space.Log(agent.HasPath)

--Return has path or not.


Height

float Height {get; set;}

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

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Height = 60

--set height to 60.



IsOnNavMesh

bool IsOnNavMesh {get;}

Is the agent currently bound to the navmesh?

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
Space.Log(agent.IsOnNavMesh)

--output this agent is on the navmesh.


IsOnOffMeshLink

bool IsOnOffMeshLink {get;}
Is the agent currently positioned on an OffMeshLink?
agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
Space.Log(agent.IsOnOffMeshLink)

--output this agent is on off meshlink.


IsPathStale

bool IsPathStale {get;}

Is the current path stale?

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
Space.Log(agent.IsPathStale)

--output the path is stale.


NextPosition

SVector NextPosition {get; set;}

Get or set the simulation position of the navmesh agent.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
function OutputNextPosition()
    Space.Log(agent.NextPosition)
end
agentobject.SubscribeToEvents()
agentobject.OnUpdate(OutputNextPosition)
--register update events to navmesh agent's game object
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


PathEndPosition

SVector PathEndPosition {get;}

End positon of navigation.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
Space.Log(agent.PatchEndPosition)

--output the end position of the navmesh agent.



PathPending

bool PathPending {get;}

Is a path in the process of being computed but not yet ready?

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
function OutputPathPending()
    Space.Log(agent.PathPending)
end
agentobject.SubscribeToEvents()
agentobject.OnUpdate(OutputPathPending)
--register update events to navmesh agent's game object
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


Radius

float Radius {get; set;}

The avoidance radius for the agent.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Radius = 5

--set radius of agent to 5.


RemainingDistance

float RemainingDistance {get;}

The distance between the agent's position and the destination on the current path.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
function OutputRemainingDistance()
    Space.Log(agent.RemainingDistance)
end
agentobject.SubscribeToEvents()
agentobject.OnUpdate(OutputRemainingDistance)
--register update events to navmesh agent's game object
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


Speed

float Speed {get; set;}

Maximum movement speed when following a path.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Speed = 20
--set speed to 20.
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


SteeringTarget

SVector SteeringTarget {get;}

Get the current steering target along the path.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
--set destination.
Space.Log(agent.SteeringTarget.ToString())

--output steering target position.


StoppingDistance

float StoppingDistance {get; set;}

Stop within this distance from the target position.

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.StoppingDistance = 2

--set stopping distance.


UpdatePosition

bool UpdatePosition {get; set;}Get or set whether the transform position is synchronized with the simulated agent position.

No documentation

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.UpdatePosition = false
--set update position to false.
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


UpdatePosition

bool UpdatePosition {get; set;}Should the agent update the transform orientation?

No documentation

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
agent.UpdateRotation = false
--set update Rotation to false.
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.


Velocity

SVector Velocity {get;}

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

agentobject = Space.Scene.Find("Cube")

agent = agentobject.NavMeshAgent
if agent == nil then
    agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
function OutputVelocity()
    Space.Log("Velocity is : " .. agent.Velocity.ToString())
end
agentobject.SubscribeToEvents()
agentobject.OnUpdate(OutputRemainingDistance)
--register update events to navmesh agent's game object
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition

--set destination.