Skip to main content
added 6 characters in body
Source Link

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    line.SetPosition(0, transform.position); //set the line's origin

    agent.SetDestination(target.position); //create the path
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(agent.path);

    agent.Stop();//add this if you don't want to move the agent
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 1; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view.

Hope this helps.

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    line.SetPosition(0, transform.position); //set the line's origin

    agent.SetDestination(target.position); //create the path
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);

    agent.Stop();//add this if you don't want to move the agent
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 1; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view.

Hope this helps.

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    line.SetPosition(0, transform.position); //set the line's origin

    agent.SetDestination(target.position); //create the path
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(agent.path);

    agent.Stop();//add this if you don't want to move the agent
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 1; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view.

Hope this helps.

deleted 358 characters in body; added 18 characters in body
Source Link

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    var path :line.SetPosition(0, NavMeshPath;transform.position); //holdset the pathline's origin

    agent.CalculatePathSetDestination(target.position, path); //create the path, but don't move
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);

    agent.Stop();//add this if you don't want to move the agent
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 0;1; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view. If this doesn't work, change

    agent.CalculatePath(target.position, path);

to

    agent.SetDestination(target.position);

Then also remove

    var path : NavMeshPath;

and change

    DrawPath(path);

to

    DrawPath(agent.path);

If you don't want the agent to move immediately, add

    agent.Stop();

after you call

    DrawPath(agent.path);

Hope this helps.

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    var path : NavMeshPath; //hold the path
    agent.CalculatePath(target.position, path); //create the path, but don't move
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 0; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view. If this doesn't work, change

    agent.CalculatePath(target.position, path);

to

    agent.SetDestination(target.position);

Then also remove

    var path : NavMeshPath;

and change

    DrawPath(path);

to

    DrawPath(agent.path);

If you don't want the agent to move immediately, add

    agent.Stop();

after you call

    DrawPath(agent.path);

Hope this helps.

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    line.SetPosition(0, transform.position); //set the line's origin

    agent.SetDestination(target.position); //create the path
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);

    agent.Stop();//add this if you don't want to move the agent
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 1; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view.

Hope this helps.

fixed grammer
Source Link

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to youyour nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    var path : NavMeshPath; //hold the path
    agent.CalculatePath(target.position, path); //create the path, but don't move
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 0; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view. If this doesn't work, change

    agent.CalculatePath(target.position, path);

to

    agent.SetDestination(target.position);

Then also remove

    var path : NavMeshPath;

and change

    DrawPath(path);

to

    DrawPath(agent.path);

If you don't want the agent to move immediately, add

    agent.Stop();

after you call DrawPath();

    DrawPath(agent.path);

Hope this helps.

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to you nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    var path : NavMeshPath; //hold the path
    agent.CalculatePath(target.position, path); //create the path, but don't move
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 0; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view. If this doesn't work, change

    agent.CalculatePath(target.position, path);

to

    agent.SetDestination(target.position);

Then also remove

    var path : NavMeshPath;

and change

    DrawPath(path);

to

    DrawPath(agent.path);

If you don't want the agent to move immediately, add

    agent.Stop();

after you call DrawPath();

Hope this helps.

It's actually really simple. First you put a line renderer component on your nav mesh agent object. If you notice, there is an array called positions. So if you attach the following script to your nav mesh agent, it will create a path between the nav mesh agent's origin and the destination.

var line : LineRenderer; //to hold the line Renderer
var target : Transform; //to hold the transform of the target
var agent : NavMeshAgent; //to hold the agent of this gameObject

function Start(){
    line = GetComponent(LineRenderer); //get the line renderer
    agent = GetComponent(NavMeshAgent); //get the agent
    getPath();
}

function getPath(){
    var path : NavMeshPath; //hold the path
    agent.CalculatePath(target.position, path); //create the path, but don't move
    yield WaitForEndOfFrame(); //wait for the path to generate
    
    DrawPath(path);
}

function DrawPath(path : NavMeshPath){
    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        return;
    
    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners
    
    for(var i = 0; i < path.corners.Length; i++){
        line.SetPosition(i, path.corners[i]); //go through each corner and set that to the line renderer's position
    }
}

So that will create a path in the game view. If this doesn't work, change

    agent.CalculatePath(target.position, path);

to

    agent.SetDestination(target.position);

Then also remove

    var path : NavMeshPath;

and change

    DrawPath(path);

to

    DrawPath(agent.path);

If you don't want the agent to move immediately, add

    agent.Stop();

after you call

    DrawPath(agent.path);

Hope this helps.

added 4 characters in body
Source Link
Loading
Source Link
Loading