public override Vector3 MoveToTargetLateralPos(Transform xform, Vector3 target, Vector3 eTarget, FlyingDroneScript scr)
	{
        if (mvState == MoveState.turn)
        {
		    // Calculate the new rotation.
		    float dot   = GeometryClass.DotToTarget2D(xform, target);
            if (dot < scr.dotTolerance)
            {
                // Calculate the new rotation.
                Vector3 angles = xform.localEulerAngles;
                float yAngle = angles.y;
                Transform tempXform = xform;
                tempXform.LookAt(target);
                float yAngleTarget = tempXform.localEulerAngles.y;
                scr.journeyFracRotate += scr.journeyDeltaRotate;
                float yAngleChanged = Mathf.LerpAngle(yAngle, yAngleTarget, GeometryClass.MapToCurve(scr.journeyFracRotate));
                angles.y = yAngleChanged;
                xform.localEulerAngles = angles;
                
            }
            else
            {
                mvState = MoveState.move;
                scr.ResetJourney();
            }
		} else { // mvState == MoveState.move
			// Calculate new position only if rotation is already correct.
            scr.journeyFracHoriz += scr.journeyDeltaHoriz;
            Vector3 newPos = Vector3.Lerp(xform.transform.position, eTarget, GeometryClass.MapToCurve(scr.journeyFracHoriz));
            xform.position = newPos;
		}
		return xform.position;
	}
 public override Vector3 MoveToTargetLateralPos(Transform xform, Vector3 target, Vector3 eTarget, FlyingDroneScript scr)
 {
     // Calculate the new position.
     Vector3 newPos = Vector3.SmoothDamp(xform.position, eTarget, ref scr.smoothVelocity, scr.smoothTime, scr.smoothMaxSpeed);
     xform.position = newPos;
     // Calculate the new rotation.
     Vector3 angles = xform.localEulerAngles;
     float yAngle = angles.y;
     Transform tempXform = xform;
     tempXform.LookAt(target);
     float yAngleTarget = tempXform.localEulerAngles.y;
     float yAngleChanged = Mathf.SmoothDampAngle(yAngle, yAngleTarget, ref scr.smoothVelocityf, scr.smoothTimeRotate, scr.smoothMaxSpeedRotate);
     angles.y = yAngleChanged;
     xform.localEulerAngles = angles;
     return xform.position;
 }
Пример #3
0
	public override Vector3 MoveToTargetLateralPos(Transform xform, Vector3 target, Vector3 eTarget, FlyingDroneScript scr)
	{
		// Calculate the new position.
        scr.journeyFracHoriz += scr.journeyDeltaHoriz;
        Vector3 newPos = Vector3.Lerp(xform.position, eTarget, GeometryClass.MapToCurve(scr.journeyFracHoriz));
        xform.position = newPos;
		// Calculate the new rotation.
		Vector3 angles = xform.localEulerAngles;
		float yAngle = angles.y;
		Transform tempXform = xform;
		tempXform.LookAt(target);
		float yAngleTarget = tempXform.localEulerAngles.y;
        scr.journeyFracRotate += scr.journeyDeltaRotate;
        float yAngleChanged = Mathf.LerpAngle(yAngle, yAngleTarget, GeometryClass.MapToCurve(scr.journeyFracRotate));
        angles.y = yAngleChanged;
		xform.localEulerAngles = angles;
		return xform.position;
	}
 public override void BeginLateralJourney(FlyingDroneScript scr)
 {
     mvState = MoveState.turn;
     scr.ResetJourney();
 }
Пример #5
0
 public override void BeginLateralJourney(FlyingDroneScript scr)
 {
     scr.ResetJourney();
 }
	public override void AdvanceWaypoints(GameObject waypointReached, Vector3 target, FlyingDroneScript scr)
	{
		scr.prevWaypoint = waypointReached;
		DroneWaypointScript wpScr = scr.prevWaypoint.GetComponent<DroneWaypointScript>();
		scr.nextWaypoint = wpScr.NearestConstrainedNeighborToPoint(target);
	}
	public override Vector3 GetEffectiveTarget(Transform xform, Vector3 target, FlyingDroneScript scr)
	{
        Vector3 eTarget = scr.nextWaypoint.transform.position;
        eTarget.y += scr.heightAboveWaypoint;
		return eTarget;
	}
	public override void AdvanceWaypoints(GameObject waypointReached, Vector3 target, FlyingDroneScript scr)
	{
		scr.RandomNextWaypoint();
	}
 public abstract void BeginLateralJourney(FlyingDroneScript scr);
Пример #10
0
	void Start()
	{
		drScript = theDrone.GetComponent<FlyingDroneScript>();
	}
    // Return the "effective target" based on the actual target.  When motion is constrained, the
    // effective target may be different.
	public abstract Vector3 GetEffectiveTarget(Transform xform, Vector3 target, FlyingDroneScript scr);
    // Any initialization that may be required for effective target calculations.
	public abstract void    DroneTargetInit(FlyingDroneScript scr);
    // Advance waypoints for patrolling or constrained following.
	public abstract void    AdvanceWaypoints(GameObject waypointReaached, Vector3 target, FlyingDroneScript scr);
 public override void BeginLateralJourney(FlyingDroneScript scr)
 {
     // No special setup needed.
 }
	public abstract Vector3 MoveToTargetLateralPos(Transform xform, Vector3 target, Vector3 eTarget, FlyingDroneScript scr);
Пример #16
0
	public override Vector3 GetEffectiveTarget(Transform xform, Vector3 target, FlyingDroneScript scr)
	{
		return target;
	}
	public override Vector3 GetEffectiveTarget(Transform xform, Vector3 target, FlyingDroneScript scr)
	{
		Vector3 closePnt, closePntNext, closePntPrev, result;
		float delta = 1.0f;  // small distance for comparisons.
		/*
		 * Get the line from prev to next waypoint.
		 * Find the closest point of the target to that line.
		 * If that closest point is one of the endpoints of the line, 
         * that is the effective target.
		 * Otherwise check the current line and each adjacent line 
         * and determine which line is closest to target.
		 * If it is one of the other lines, the effective target is the common waypoint (next or prev).
		 * Otherwise, if the closest line is the current line, the effective target is the 
         * closest point on that line.
		 */
		GameObject nextWP = scr.nextWaypoint;
		GameObject prevWP = scr.prevWaypoint;
		Vector3 Pnext = nextWP.transform.position;
		Vector3 Pprev = prevWP.transform.position;
		DroneWaypointScript nextWPscr = nextWP.GetComponent<DroneWaypointScript>();
		DroneWaypointScript prevWPscr = prevWP.GetComponent<DroneWaypointScript>();

        // Is Pprev the effective target?  If so, return it.
		closePnt = GeometryClass.ClosestPointOnLine(Pprev, Pnext, target, true);
        if (Vector3.Distance(Pprev, target) < delta)
            result = Pprev;

        // Is Pnext the effective target?  If so, return it.
        else if (Vector3.Distance(Pnext, target) < delta)
            result = Pnext;

        else
        {

            // Get the distance of the target point to the current line.
            float distCurLine = Vector3.Distance(closePnt, target);

            // Get the line connected to the next WP that is closest to the target.
            GameObject closestWPtoNextWP = nextWPscr.NearestConstrainedNeighborToPoint(target);
            // Get the closest point on that line.
            closePntNext = GeometryClass.ClosestPointOnLine(Pnext, closestWPtoNextWP.transform.position, target, true);
            // Get the distance from that point to the target.
            float distNextLines = Vector3.Distance(closePntNext, target);

            // Get the line connected to the prev WP that is closest to the target.
            GameObject closestWPtoPrevWP = prevWPscr.NearestConstrainedNeighborToPoint(target);
            // Get the closest point on that line.
            closePntPrev = GeometryClass.ClosestPointOnLine(Pprev, closestWPtoPrevWP.transform.position, target, true);
            // Get the distance from that point to the target.
            float distPrevLines = Vector3.Distance(closePntPrev, target);

            // If the target is closer to a line adjecent to the next waypoint than to a line joining prev and 
            // next waypoints and to a line adjacent to the prev waypoint,
            // return the next waypoint.
            if (distNextLines < distCurLine && distNextLines < distPrevLines)
                result = Pnext;

            // If the target is closer to a line adjecent to the prev waypoint than to a line joining prev and 
            // next waypoints and to a line adjacent to the next waypoint,
            // return the prev waypoint.
            else if (distPrevLines < distCurLine && distPrevLines < distNextLines)
                result = Pprev;

            // If we have gotten this far, return the closest point on the line joining prev and next waypoints.
            else
                result = closePnt;
        }
        // Adjust result by heightAboveWaypoint.
        result.Set(result.x, result.y+scr.heightAboveWaypoint, result.z);
        return result;
	}
	public override void DroneTargetInit(FlyingDroneScript scr)
	{
	}
	public override void DroneTargetInit(FlyingDroneScript scr)
	{
		scr.UpdateClosestWaypoints();
	}
Пример #20
0
    /*
	 * Functions that implement the Unity callbacks Start() and FixedUpdate().
	 */

    void Start()
    {
        // Get the specific script for this drone.
        thisScript = gameObject.GetComponent<FlyingDroneScript>();
        droneScr = gameObject.GetComponent<FlyingDroneSpecificScript>();

        InitializeModes();

        // Force initial state to be what user has selected in the Inspector.
        SetUserTravelAndMotion(true);
        SetUserMode(true);

        // Start the Finite State Machine (FSM).
        //EnterStartState();
        SetHoverMode();

        InvokeRepeating("CheckFolloweeMoved", 0.5f, 1.0f);
    }
Пример #21
0
 // Advance waypoints for patrolling or constrained following.
 public abstract void    AdvanceWaypoints(GameObject waypointReaached, Vector3 target, FlyingDroneScript scr);