Example #1
0
   public void MoveToDestination(Vector3 destPoint){
		if(!Pathfinding.DataLoaded()){
			Debug.Log ("Navigation data is not loaded!");
			return;
		}
		if(destPoint == Vector3.zero){
			Debug.Log ("destination point is Vector3.zero, use value different from 0 for one of coordinates of destPoint,example: new Vector3(0.0000000001,0,0)");
			return;
		}
		if(!movement){
			Debug.Log ("NPCMovement component not found on this transform! Can't move anywhere!");
			return;
		}
		if(types.Length<1){
			Debug.Log ("paths types array is empty! Can't move by any path!");
			return;
		}
		if(!Pathfinding.ObjectIsVisible(destPoint,This.position,thisRadius,movement.layerMask)){
			if(!routeData.IsNotValid())
				if(!Pathfinding.ObjectIsVisible(destPoint,Pathfinding.GetWaypointInSpace(0.5f,routeData.destinationNode),thisRadius,movement.layerMask))
					routeData = new Pathfinding.RouteData();
			if(routeData.IsNotValid()){
				movement.targetPoint = Vector3.zero;
				targetPointValue = -1f;
				routeData = Pathfinding.GetRouteForPoint(routeData,types,destPoint,This.position,thisRadius,movement.layerMask2);
			}
			FollowRoute ();
			destinationPointIsVisible = false;
		}else{
			if(!routeData.IsNotValid())
				routeData = new Pathfinding.RouteData();
			movement.targetPoint = ApplyVector3(movement.targetPoint,destPoint,targetPointConstraints);
			destinationPointIsVisible = true;
		}
		distanceToDestinationPoint = Vector3.Distance (This.position,destPoint);
	}
Example #2
0
	void DrawAtypicalSelectedPaths(){
		if(!drawCustomPath)
	     return;
		if(Time.time>drawTime){
		drawTime = Time.time+0.1f;	
		}else return;
		if(Pathfinding.newAtypicalPaths.nodes.Length<1)
			return;
		if(startPoint.number == endPoint.number && startPoint.type == endPoint.type)
			return;
		//Debug.Log ("Request route: startPoint number="+startPoint.number+" of type "+startPoint.type);
		//Debug.Log ("			   endPoint number="+endPoint.number+" of type "+endPoint.type);
		int i;
		Pathfinding.Node prev = new Pathfinding.Node(startPoint.number,startPoint.type);
		routeData.curNode = new Pathfinding.Node(startPoint.number,startPoint.type);
		routeData.destinationNode = new Pathfinding.Node(endPoint.number,endPoint.type);
		routeData.nextNode = new Pathfinding.Node(-1,"");
		routeData.nextNodeIndex = 0;
        routeData = Pathfinding.GetNextNode(routeData);
		for(i=0;i<34567;i++){
Debug.DrawLine(Pathfinding.GetWaypointInSpace(0.5f,prev.number,prev.type),Pathfinding.GetWaypointInSpace(0.5f,routeData.curNode.number,routeData.curNode.type),Color.blue,0.1f);	
		if(routeData.curNode.number == routeData.destinationNode.number)
			if(routeData.curNode.type == routeData.destinationNode.type)
				break;
		//Debug.Log ("prev:"+prev.number.ToString ()+prev.type+"; curPoint:"+routeData.curPoint.number.ToString ()+routeData.curPoint.type);
			prev = new Pathfinding.Node(routeData.curNode.number,routeData.curNode.type);
			//Debug.Log ("Calculate new cur point(step "+i+")");
		routeData = Pathfinding.GetNextNode(routeData);
		}
		
	}
Example #3
0
	void FollowRoute(){
		if(routeData.IsNotValid ()){
			Debug.Log (This.name+": routeData is not valid, can't follow route!");
			failCounter++;
			return;
		}
		//check visibility of next point,because if it already visible, we can start moving to it
		if(useVisibility)
			pointVisibility = Pathfinding.VisibilityOfNode(routeData.nextNode,This.position,thisRadius,movement.layerMask2);
		else pointVisibility =-1;
		//if visible
		if(useNodeDistance)
			distToCurPoint = Pathfinding.DistanceToNode(routeData.curNode,This.position);
		else
			distToCurPoint = Vector3.Distance (This.position,movement.targetPoint);

		if(pointVisibility>0 || distToCurPoint<=pointReachRadius){
			//then update currrent point and next point (curPoint = nextPoint,get new nextPoint)
			routeData = Pathfinding.GetNextNode(routeData);
			//reset trajectory update time
			if(!Pathfinding.NodesEqual(routeData.nextNode,routeData.destinationNode)){
			trajectoryUpdateTime = 0f;
			//reset curPoint presentation value(this value represent point inside curPoint node, if
			// curPoint is bipoint
			targetPointValue = -1f;
			}
			//reset movement interpolation point(do this on each curPoint update)
			//Movement.ResetMovement();
		}
		//now check visibility of current node
		pointVisibility = Pathfinding.VisibilityOfNode(routeData.curNode,This.position,thisRadius*0.6f,movement.layerMask2);
		//if visible
		if(pointVisibility>0){
			//and current node is single point, or half-visible bipoint
			if(pointVisibility==0 || pointVisibility == 1){
				//then move to center of this bipoint or single point
				targetPointValue = 0.5f;
				//reset trajectory update time
				trajectoryUpdateTime = 0f;
			}
			//in other case, if current point is fully visible bipoint and we can update trajectory
			else if(curTime>trajectoryUpdateTime){
				//then get new target point value
				targetPointValue = Pathfinding.GetOptimizedTrajectoryPoint(routeData.curNode,routeData.nextNode,
				                                                           targetPointValue,pathOptimization,This.position,Random.Range(0.5f,1f),5f,0.2f); //Random.Range(0.5f,1f),5f,0.2f
				//set next trajectory update time
				trajectoryUpdateTime = curTime + trajectoryUpdateInterval;
			}
			//set real movement point  by transforming targetPointValue into point in space
			//temporary line below, delete this
			//targetPointValue = 0.5f;
			movement.targetPoint = ApplyVector3(movement.targetPoint,Pathfinding.GetWaypointInSpace(targetPointValue,routeData.curNode),targetPointConstraints);
		}
		//if current point are lost and is not visible anymore
		else{
			//then  build new route to destination point
			//get new current point
			routeData = Pathfinding.ResumeRoute(routeData,types,This.position,thisRadius,movement.layerMask2);
			trajectoryUpdateTime = 0f;
			//reset movement interpolation point
			movement.ResetMovement();
		}
		//Draw current point direction
		Debug.DrawLine(This.position,movement.targetPoint,Color.yellow);	
		//Draw next point direction
		Debug.DrawLine(movement.targetPoint,Pathfinding.GetWaypointInSpace(0.5f,routeData.nextNode),Color.red);		
		
	}
Example #4
0
	void GetRoute(){
	routeData = new Pathfinding.RouteData();
	routeData.route = Pathfinding.GetRoute(types,startPoint,endPoint);
	routeData.curNode = new Pathfinding.Node(startPoint.number,startPoint.type);
	routeData.destinationNode = new Pathfinding.Node(endPoint.number,endPoint.type);
	routeData.nextNodeIndex = 0;
	routeData.nextNode = new Pathfinding.Node(-1,"");
	}