예제 #1
0
 public override void UpdateState()
 {
     if (!canInterrupt && loopOmega * (Time.time - startTime) >= 2 * Math.PI)
     {
         executedManeuver = new MakeCircle(executedManeuver.CalculateWorldPosition(), executedManeuver.CalculateWorldRotation(), circleOmega, circleRadius);
         canInterrupt     = true;
     }
 }
 //in the future, we can add different radii and omegas for the different stages of the attack; in the meantime, we'll just use one set for simplicity
 public AttackBuildingManeuver(Vector3 currentPosition, Quaternion currentRotation, Vector3 CoordsToAttack, GameObject building, float flightSpeed = GlobalManager.defaultAttackSpeed, float radius = GlobalManager.defaultCircleRadius, float omega = GlobalManager.defaultCircleOmega)
 {
     alphaOnTargetRecord = GameObject.Find("AlphaOnTarget").GetComponent <AudioSource>();
     AttackCoords        = CoordsToAttack;
     AttackCoords.y      = AttackCoords.y + GlobalManager.heightAboveBuildingToAttack;
     initialPosition     = currentPosition;
     initialRight        = currentRotation * Vector3.right;
     this.flightSpeed    = flightSpeed;
     this.radius         = radius;
     this.omega          = omega;
     executedManeuver    = new MakeCircle(currentPosition, currentRotation, omega, radius);
     initialPosition     = currentPosition;
     initialRight        = currentRotation * Vector3.right;
     this.building       = building;
     MapCommands.Instance.LockMap();
 }
        public override void UpdateState()
        {
            executedManeuver.UpdateState();
            Vector3    position = executedManeuver.CalculateWorldPosition();
            Quaternion rotation = executedManeuver.CalculateWorldRotation();

            if (stage == (int)stagesOfAttack.initialAttackCircle && Vector3.Angle(rotation * Vector3.forward, position - new Vector3(AttackCoords.x, position.y, AttackCoords.z)) < permissibleAngleErrorDegrees)
            {
                stage = (int)stagesOfAttack.straightFlightToTarget;
                Vector3 planesRight = rotation * Vector3.right;
                planesRight.y = 0;
                planesRight.Normalize();
                finalCoords = position - 2 * radius * planesRight;
                //the "forward" vector in the LookRotation call is multpiplied by -1 because the forward vector of the Hercules model is towards its tail
                executedManeuver = new StraightFlightManeuver(position, AttackCoords, flightSpeed, rotation);
            }
            if (stage == (int)stagesOfAttack.straightFlightToTarget && ((StraightFlightManeuver)executedManeuver).finished)
            {
                stage = (int)stagesOfAttack.circleSegmentAboveTarget;
                try
                {
                    building.GetComponent <BuildingDisplay>().BoomBuilding();
                }
                catch { }
                MapCommands.Instance.UnlockMap();
                executedManeuver = new MakeCircle(position, rotation, omega, radius);
                //Vector3[] pos = { new Vector3() };
                //line.SetPositions(pos);
                line.SetActive(false);
            }
            if (stage == (int)stagesOfAttack.circleSegmentAboveTarget && Vector3.Angle(rotation * Vector3.forward, position - new Vector3(finalCoords.x, position.y, finalCoords.z)) < permissibleAngleErrorDegrees)
            {
                stage            = (int)stagesOfAttack.straightFlightBackToCircle;
                executedManeuver = new StraightFlightManeuver(position, finalCoords, flightSpeed, rotation);
            }
            if (stage == (int)stagesOfAttack.straightFlightBackToCircle && ((StraightFlightManeuver)executedManeuver).finished)
            {
                alphaOnTargetRecord.Play();
                stage            = (int)stagesOfAttack.finalCircle;
                executedManeuver = new MakeCircle(position, rotation, omega, radius);
            }
        }