public NavigationTree(FighterBlackboard blackboard, Navigator navigator, Propulsion prop)
        {
            m_blackboard = blackboard;
            m_propulsion = prop;
            m_topSpeed   = prop.thrust * 5; // this is just bad

            AddBehaviour <Behaviour>().BUpdate = GetDestinationToTarget;
            Selector shootOrTraverse = AddBehaviour <Selector>();

            {
                // completely redundant
                //Sequence shoot = shootOrTraverse.AddBehaviour<Sequence>();
                //{
                //    shoot.AddBehaviour<Condition>().BCanRun = TargetEnteringRange;
                //    shoot.AddBehaviour<Behaviour>().BUpdate = TurnToTarget;
                //}

                Sequence traverse = shootOrTraverse.AddBehaviour <Sequence>();
                {
                    traverse.AddBehaviour <Behaviour>().BUpdate = Stabilize;
                    traverse.AddBehaviour <Behaviour>().BUpdate = SetDestination;
                    Sequence stayInFormation = traverse.AddBehaviour <Sequence>();
                    {
                        stayInFormation.AddBehaviour <Condition>().BCanRun = HasWingman;
                        stayInFormation.AddBehaviour <Behaviour>().BUpdate = VectoringThrust;
                    }
                }
                shootOrTraverse.AddBehaviour <Behaviour>().BUpdate = CommonBehaviours.AlwaysSucceed;
            }

            AddBehaviour <Behaviour>().BUpdate = SetThrottle;
        }
Beispiel #2
0
        public void SetYoke(FighterBlackboard blackboard, Vector3 destination)
        {
            this.destination = destination;

            float pitchAngle = Mathf.Asin(Vector3.Cross(this.destination.normalized, blackboard.parentObject.transform.forward).x) * Mathf.Rad2Deg;
            float yawAngle   = Mathf.Asin(Vector3.Cross(this.destination.normalized, blackboard.parentObject.transform.forward).y) * Mathf.Rad2Deg;

            // float rollAngle  = Mathf.Asin(Vector3.Cross(targetDirection.normalized, blackboard.parentObject.transform.forward).z) * Mathf.Rad2Deg;

            // Add 90 degrees to Arcsin curve if destination is behind transform
            if (Vector3.Distance(destination, blackboard.parentObject.transform.position) <
                Vector3.Distance(destination, blackboard.parentObject.transform.position + blackboard.parentObject.transform.forward * .01f))
            {
                // some inaccuracy at 90-95 degrees due to checking slightly in front of transform
                // Debug.Log("testTarget is behind transform");
                if (pitchAngle != 0)
                {
                    pitchAngle = (pitchAngle > 0) ? (180 - pitchAngle) : (-180 + Mathf.Abs(pitchAngle));
                }
                if (yawAngle != 0)
                {
                    yawAngle = (yawAngle > 0) ? (180 - yawAngle) : (-180 + Mathf.Abs(yawAngle));
                }
            }

            Vector3 localVelocity = blackboard.parentObject.transform.InverseTransformDirection(m_propulsion.rigidbody.angularVelocity);

            // Debug.Log("amount of Pitch: " + - (pitchAngle + (localVelocity.x * Mathf.Rad2Deg)) + " /// amount of Yaw: " + -(pitchAngle + (localVelocity.y * Mathf.Rad2Deg)));
            m_yoke.x = -(pitchAngle + (localVelocity.x * Mathf.Rad2Deg)) / 180;
            m_yoke.y = -(yawAngle + (localVelocity.y * Mathf.Rad2Deg)) / 180;
            m_yoke.z = 0;
        }
        public ScanningBehaviour(FighterBlackboard blackboard)
        {
            m_blackboard = blackboard;

            Sequence GetWingman = AddBehaviour <Sequence>();
            {
                GetWingman.AddBehaviour <Behaviour>().BUpdate = TargetClosestFriendly;
                // all that squadron stuff
            }

            Selector engageOrRetreat = AddBehaviour <Selector>();
            {
                Sequence engage = engageOrRetreat.AddBehaviour <Sequence>();
                {
                    engage.AddBehaviour <Condition>().BCanRun = HasEnemy;
                    engage.AddBehaviour <Behaviour>().BUpdate = TargetClosestEnemy;
                }

                Selector retreat = engageOrRetreat.AddBehaviour <Selector>();
                {
                    Sequence goHome = retreat.AddBehaviour <Sequence>();
                    {
                        goHome.AddBehaviour <Condition>().BCanRun = HasMothership;
                        goHome.AddBehaviour <Behaviour>().BUpdate = TargetMothership;
                    }
                    goHome.AddBehaviour <Behaviour>().BUpdate = TargetEnemyMothership;
                }

                engageOrRetreat.AddBehaviour <Behaviour>().BUpdate = CommonBehaviours.AlwaysSucceed;
            }
        }
        public WeaponBehaviour(FighterBlackboard blackboard, Weapon weapon)
        {
            m_blackboard = blackboard;
            m_weapon     = weapon;

            AddBehaviour <Condition>().BCanRun = HasTarget;
            AddBehaviour <Condition>().BCanRun = IsTargetingEnemy;
            AddBehaviour <Behaviour>().BUpdate = Reloading;
            AddBehaviour <Behaviour>().BUpdate = TakingAim;
            AddBehaviour <Behaviour>().BUpdate = OpeningFire;
        }