/// <summary> /// Constructor for the Flight class that allows creation with explicit X and Y values /// </summary> /// <param name="name">Flight Name</param> /// <param name="model">Aircraft Model</param> /// <param name="type">Flight Type</param> /// <param name="dest">Destination Navpoint</param> /// <param name="altitude">Current altitude</param> /// <param name="speed">Current speed</param> /// <param name="heading">Current heading</param> /// <param name="x">Current Location on the X-axis</param> /// <param name="y">Current Location on the Y-axis</param> public Flight(string name, AircraftModel model, FlightPhase type, ref Waypoint dest, int altitude = 0, int speed = 0, int heading = 0, double x = 0, double y = 0) { this._name = name; this._model = model; this._type = type; this._destination = dest; this._altitude = altitude; this._speed = speed; this._heading = heading; this._location = new Location(x, y); this._targetAltitude = 0; }
public void SetTarget(Transform newTarget) { target = newTarget; if (newTarget != null) { targetPosition = target.position; phase = FlightPhase.ToTarget; if (withEnvelopeMaterial != null) { GetComponent <MeshRenderer>().materials = new Material[] { withEnvelopeMaterial }; } } else { rb = GetComponent <Rigidbody>(); rb.velocity = Vector3.zero; } }
// Update is called once per frame void FixedUpdate() { if (target == null) { return; } Vector3 toTarget = targetPosition - rb.position; FlapIfNeeded(toTarget); Vector3 horizontalDelta = toTarget; horizontalDelta.y = 0; //Vector3 delta = toTarget.normalized * Time.deltaTime * speed; //rb.MovePosition(rb.position + delta); rb.MoveRotation(Quaternion.LookRotation(horizontalDelta)); switch (phase) { case FlightPhase.ToTarget: if (horizontalDelta.magnitude < 1) { dropPayload(); this.phase = FlightPhase.BackHome; targetPosition = initialPosition; } return; case FlightPhase.BackHome: if (horizontalDelta.magnitude < 1) { SetTarget(null); } break; } }