Esempio n. 1
0
 public void OnAvoidanceAreaExit()
 {
     switch ( this.currentAvoidanceState )
     {
     case AVOIDANCE_STATE.NONE:
         break;
     case AVOIDANCE_STATE.DOWN_RETURN:
         break;
     case AVOIDANCE_STATE.UP_RETURN:
         break;
     case AVOIDANCE_STATE.UP_START:
         this.currentAvoidanceState = AVOIDANCE_STATE.UP_RETURN;
         break;
     case AVOIDANCE_STATE.DOWN_START:
         this.currentAvoidanceState = AVOIDANCE_STATE.DOWN_RETURN;
         break;
     default:
         DebugConsole.Error( "Uncaught state " + this.currentAvoidanceState );
         break;
     }
 }
Esempio n. 2
0
    private void UpdateAvoidanceControl()
    {
        if ( this.isFollowingAvoidanceCurve )
        {
            float oldPos = this.currentAvoidCurvePoint;
            this.currentAvoidCurvePoint += this.currentMovementSpeed * Time.deltaTime;

            if ( this.currentAvoidCurvePoint >= this.avoidCurveLength )
            {
                this.EndAvoidanceCurve();
            }
            else
            {
                float t1 = this.currentAvoidCurvePoint / this.avoidCurveLength;
                float t2 = oldPos / this.avoidCurveLength;

                float d1 = Common.SmoothPingPong( t1, this.avoidanceCurveStartHeight, this.avoidanceCurveEndHeight, 1 );
                float d2 = Common.SmoothPingPong( t2, this.avoidanceCurveStartHeight, this.avoidanceCurveEndHeight, 1 );

                this.currentAvoidHeight = d1;
                this.currentAvoidAngle = Mathf.Atan2( d2-d1, t1-t2 ) * this.avoidanceAngleMultiplier;
            }
        }
        else
        {
            switch ( this.currentAvoidanceState )
            {
            case AVOIDANCE_STATE.NONE:
            {
                break;
            }
            case AVOIDANCE_STATE.DOWN_RETURN:
            {
                if ( this.currentAvoidHeight >= 0 )
                {
                    // Flatten off and finish up
                    this.currentAvoidanceState = AVOIDANCE_STATE.NONE;
                    this.currentAvoidAngle = 0.0f;
                    this.currentAvoidHeight = 0.0f;
                    break;
                }
                // If nose is down, bring it back up
                else if ( this.currentAvoidAngle <= 0.0f )
                {
                    this.currentAvoidAngle += Time.deltaTime * this.avoidanceAngleRate;
                    this.currentAvoidHeight -= this.GetAvoidanceHeightSpeed() * Time.deltaTime;
                }

                if ( this.currentAvoidAngle >= 0.0f )
                {
                    this.StartAvoidanceCurve( 0.0f );
                }
                break;
            }
            case AVOIDANCE_STATE.DOWN_START:
            {
                if ( this.currentAvoidHeight == this.avoidanceFloor )
                {
                    break;
                }
                // If the nose is pointing up, nose down
                if ( this.currentAvoidAngle < 0.0f )
                {
                    this.currentAvoidAngle += Time.deltaTime * this.avoidanceAngleRate;
                    this.currentAvoidHeight -= this.GetAvoidanceHeightSpeed() * Time.deltaTime;
                }

                // If the nose is flat, start curving down
                if ( this.currentAvoidAngle >= 0.0f )
                {
                    this.StartAvoidanceCurve( this.avoidanceFloor );
                }
                break;
            }
            case AVOIDANCE_STATE.UP_RETURN:
            {
                // If we are back below normal height
                if ( this.currentAvoidHeight <= 0 )
                {
                    // Flatten off and finish up
                    this.currentAvoidanceState = AVOIDANCE_STATE.NONE;
                    this.currentAvoidAngle = 0.0f;
                    this.currentAvoidHeight = 0.0f;
                    break;
                }
                // If nose is up, bring it back down
                else if ( this.currentAvoidAngle >= 0.0f )
                {
                    this.currentAvoidAngle -= Time.deltaTime * this.avoidanceAngleRate;
                    this.currentAvoidHeight += this.GetAvoidanceHeightSpeed() * Time.deltaTime;
                }

                if ( this.currentAvoidAngle <= 0.0f )
                {
                    this.StartAvoidanceCurve( 0.0f );
                }
                break;
            }
            case AVOIDANCE_STATE.UP_START:
            {
                if ( this.currentAvoidHeight == this.avoidanceCeiling )
                {
                    break;
                }
                // If the nose is pointing down, nose up
                if ( this.currentAvoidAngle > 0.0f )
                {
                    this.currentAvoidAngle -= Time.deltaTime * this.avoidanceAngleRate;
                    this.currentAvoidHeight += this.GetAvoidanceHeightSpeed() * Time.deltaTime;
                }

                // If the nose is flat, start curving up
                if ( this.currentAvoidAngle <= 0.0f )
                {
                    this.StartAvoidanceCurve( this.avoidanceCeiling );
                }
                break;
            }
            default:
            {
                DebugConsole.Error( "Uncaught state " + this.currentAvoidanceState, this );
                return;
            }
            }
        }
        this.avoidanceTransform.localPosition = new Vector3( 0.0f, this.currentAvoidHeight, 0.0f );
        //this.avoidanceTransform.localRotation = Quaternion.Euler( this.currentAvoidAngle, 0.0f, 0.0f );
    }
Esempio n. 3
0
    public void OnAvoidanceAreaEnter( CapitalShipMovement _otherShip )
    {
        this.otherShip = _otherShip;

        if ( this.currentAvoidanceState == AVOIDANCE_STATE.UP_RETURN
          || this.currentAvoidanceState == AVOIDANCE_STATE.UP_START )
        {
            this.currentAvoidanceState = AVOIDANCE_STATE.UP_START;
        }
        else if ( this.currentAvoidanceState == AVOIDANCE_STATE.DOWN_RETURN
               || this.currentAvoidanceState == AVOIDANCE_STATE.DOWN_START )
        {
            this.currentAvoidanceState = AVOIDANCE_STATE.DOWN_START;
        }
        else
        {
            // Determine which ship is on the left or right of the intercept line
            Vector3 f1 = this.transform.forward;
            Vector3 f2 = this.otherShip.transform.forward;
            float direction = Vector3.Cross( f1, f2 ).y;

            if ( direction > 0.0f )
            {
                this.currentAvoidanceState = AVOIDANCE_STATE.DOWN_START;
            }
            else
            {
                this.currentAvoidanceState = AVOIDANCE_STATE.UP_START;
            }
        }
    }