wiki.sine.space | sinespace

Scripting/SNavMeshAgent

From wiki.sine.space
Revision as of 02:39, 22 December 2020 by Edisonwu (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.