Hello guys Unity community I was Progaming an artificial intelligence script based on NavMesh Unity but found problems.
In this script I wanted to make the character was even a wall to hide the target but that the target was found by Linecast he would seek another wall.
in scripting language I created a Linecasst starting from four points around the wall indentificate if the target was behind her, and if there would be the fate of navMeshAgent, but if not change the destination to the other side of the wall, but the unique destination that navMash this finding is the right side of one of the walls regardless of the target position.
Here is the translated script for I am Brazilian and I do not speak English !!
#pragma strict
var WallPoint1 : Transform;
var WallPoint2 : Transform;
var Wall1: Transform;
var Wall2: Transform;
//var distance1: Vector3;
//var distance2: Vector3;
var WallPosition1: Vector3;
var WallPosition2: Vector3;
var WallPointLefth: Transform;
var WallPointRigth: Transform;
var Hero: Transform;
var NavPosiTiondestination: NavMeshAgent;
function Start () {
WallPosition1= Wall1.transform.position;
WallPosition2= Wall2.transform.position;
NavPosiTiondestination=transform.GetComponent(“NavMeshAgent”);
}
function Update () {
var dist =Vector3.Distance ( WallPoint1 .position, hero.position );
var dist2 =Vector3.Distance ( WallPoint1 .position, Hero.position );
if(dist<dist2)
{
NavPosiTiondestination.destination = WallPoint.position;
if(RigthOrLefth.HaveWall==false)
{
NavPosiTiondestination.destination = WallPointrigth.position;
}
}
else
{
NavPosiTiondestination.destination = Wallpoint.position;
}
if(dist>dist2)
{
NavPosiTiondestination.destination = WallPoint2.position;
if(RigthOrLefth.HaveWall==false)
{
NavPosiTiondestination.destination = WallPointLefth.position;
}
}
else
{
NavPosiTiondestination.destination = WallPoint2.position;
}
}
Sorry for the bad translation I do not speak English well or write.
Please help me Thanks