示例#1
0
        private void ChaseTarget(ShipStateController controller)
        {
            ShipMotor shipMotor = controller.GetMotor();
            Rigidbody ship      = controller.GetRigidbody();
            Rigidbody target    = controller.GetTarget();

            if (target == null)
            {
                return;
            }

            Steer(shipMotor, ship, target);

            AdjustThrottle();

            Vector3 toTarget = target.position - ship.position;

            float angle = Vector3.Angle(ship.transform.forward, toTarget);



            Vector3 velocityDifference = ship.velocity - target.velocity;

            //Check throttle
            //Check angle from player
            //Check velocity differences
            //Adjust throttle

            //steer based on stats/throttle
        }
示例#2
0
        public override void Perform(StateController controller)
        {
            ShipStateController shipController = controller as ShipStateController;

            //Spin
            Spin(shipController);

            //Fire
            Fire(shipController);
        }
示例#3
0
        private bool LineLook(ShipStateController controller, out RaycastHit hit)
        {
            Transform shipEyes = controller.GetEyes();


            Ray ray = new Ray(shipEyes.position, shipEyes.transform.forward);

            Debug.DrawRay(ray.origin, ray.direction * controller.GetVisionRange());

            return(Physics.Raycast(ray, out hit, controller.GetVisionRange(), visionMask));
        }
示例#4
0
        void Fire(ShipStateController controller)
        {
            float timeInState = controller.GetTimeInCurrentState();

            if (timeInState > attackDelay)
            {
                Rigidbody shipRigidbody = controller.GetRigidbody();
                Ray       forward       = new Ray(shipRigidbody.position, shipRigidbody.transform.forward);

                controller.GetWeaponSystem().Fire(forward, controller.GetTarget());
            }
        }
示例#5
0
        public bool Look(ShipStateController controller, out RaycastHit hit)
        {
            switch (visionType)
            {
            case VisionType.LINE:
                return(LineLook(controller, out hit));

            case VisionType.SPHERE:
                return(SphereLook(controller, out hit));

            case VisionType.CONE:
                return(ConeLook(controller, out hit));
            }
            return(LineLook(controller, out hit));
        }
示例#6
0
        public override bool Decide(StateController controller)
        {
            ShipStateController shipController = controller as ShipStateController;

            RaycastHit hit;

            if (Look(shipController, out hit))
            {
                Debug.Log("Something is seen!");
            }

            //controller.HitToTarget();

            return(false);
        }
示例#7
0
        public override bool Decide(StateController controller)
        {
            ShipStateController shipController = controller as ShipStateController;

            //False if we haven't been in the current state long enough
            if (shipController.GetTimeInCurrentState() < stateDelay)
            {
                return(false);
            }

            Rigidbody target = controller.GetTarget();

            if (target == null)
            {
                return(false);
            }

            return(ValidatePosition(shipController, target));
        }
示例#8
0
        bool ValidatePosition(ShipStateController controller, Rigidbody target)
        {
            Rigidbody myself = controller.GetRigidbody();

            //False if too far away
            if (Vector3.Distance(myself.position, target.position) > maxRange)
            {
                return(false);
            }

            //False if we aren't facing near the target
            Vector3 towards = target.position - myself.position;

            if (Vector3.Angle(myself.transform.forward, towards) > maxAngle)
            {
                return(false);
            }

            return(true);
        }
示例#9
0
 private bool ConeLook(ShipStateController controller, out RaycastHit hit)
 {
     hit = new RaycastHit();
     return(false);
 }
示例#10
0
        public override void Perform(StateController controller)
        {
            ShipStateController shipStateController = controller as ShipStateController;

            ChaseTarget(shipStateController);
        }
示例#11
0
 void Spin(ShipStateController controller)
 {
     controller.GetMotor().Roll(1f);
 }