Exemplo n.º 1
0
Arquivo: Movements.cs Projeto: UDK/SoV
        public static void CircleAroundTarget(GameObject self, GameObject target, SpaceShipContainer container)
        {
            var distance = Vector2.Distance(
                container.Homing.transform.position,
                self.transform.position);

            if (distance > container.SightDist)
            {
                Movements.HeadToTarget(self, container.Homing, container);
                return;
            }
            Movements.MoveByCircle(self, container.Homing, container);
        }
Exemplo n.º 2
0
        public static Action SearchTarget(
            GameObject self,
            SpaceShipContainer container) =>
        () =>
        {
            Ray enemyRay = new Ray(
                self.transform.position,
                self.transform.forward * container.SightDist);

            float halfAngle = container.VisionAngle / container.RayCount * (container.RayCount * 0.5f);
            for (int i = 0; i < container.RayCount; i++)
            {
                float   angle     = i * (container.VisionAngle / (container.RayCount - 1));
                Vector3 direction = Quaternion.AngleAxis(
                    self.transform.localRotation.eulerAngles.z + angle - halfAngle,
                    self.transform.forward) * Vector3.right;

                Debug.DrawRay(self.transform.position, direction * container.SightDist, Color.red, 0.1f);
                var filter = new ContactFilter2D();
                filter.NoFilter();
                RaycastHit2D[] raycastHits = new RaycastHit2D[10];
                var            rayHit      = Physics2D.Raycast(
                    self.transform.position,
                    direction,
                    filter,
                    raycastHits,
                    container.SightDist);

                container.Targets = raycastHits.Select(x => x.collider?.gameObject).ToArray();
                foreach (var t in container.Targets)
                {
                    var go = t?.GetComponent <IGameplayObject>();
                    if (go != null &&
                        go.AllianceGuid != container.AllianceGuid)
                    {
                        container.Target = t;
                        container.StateMachine.Push(
                            States.ShipStates.Attacking);
                        return;
                    }
                }
            }

            Movements.CircleAroundTarget(self, container.Homing, container);
            Rotations.RotateBySpeed(self, container);
        };
Exemplo n.º 3
0
 private static void BombingAttackStrategy(
     GameObject self,
     SpaceShipContainer container)
 {
     container.StateMachine
     .Set(
         ShipStates.Moving,
         Middleware(
             TargetCheckMiddleware(container),
             Movements.GoAfterTarget(self, container)))
     .Set(
         ShipStates.SearchingOfTarget,
         TargetSearchings.SearchTarget(self, container))
     .Set(
         ShipStates.Attacking,
         Middleware(
             TargetCheckMiddleware(container),
             Attacks.Back(self, container)));
 }
Exemplo n.º 4
0
Arquivo: Attacks.cs Projeto: UDK/SoV
        public static Action Back(
            GameObject self,
            SpaceShipContainer container) =>
        () =>
        {
            Vector3 toTarget = (container.Target.transform.position - self.transform.position).normalized;
            var     dot      = Vector3.Dot(
                self.transform.right,
                toTarget);

            foreach (var weapon in container.Weapons)
            {
                weapon.Attack(container.Target, container.AllianceGuid);
            }
            var distance = Vector2.Distance(
                container.Target.transform.position,
                self.transform.position);

            if (dot < -0.60 &&
                distance > container.AttackDistance * 2)
            {
                container.StateMachine.Push(
                    ShipStates.Moving);
            }
            else if (dot < 0)
            {
                if (dot < -0.5)
                {
                    Movements.MoveByCircle(self, container.Target, container);
                }
                container.MovementBehaviour.SmoothlySetVelocity(
                    container.MovementBehaviour.Velocity.normalized *
                    container.MovementBehaviour.MaxVelocity);
            }
            else
            {
                Movements.MoveByCircle(self, container.Target, container);
            }

            Rotations.RotateBySpeed(self, container);
        };
Exemplo n.º 5
0
Arquivo: Attacks.cs Projeto: UDK/SoV
        public static Action CircleAround(
            GameObject self,
            SpaceShipContainer container) =>
        () =>
        {
            foreach (var weapon in container.Weapons)
            {
                weapon.Attack(container.Target, container.AllianceGuid);
            }

            var distance = Vector2.Distance(
                container.Target.transform.position,
                self.transform.position);
            if (distance > container.AttackDistance)
            {
                container.StateMachine.Push(
                    ShipStates.Moving);
                return;
            }

            Movements.MoveByCircle(self, container.Target, container);
            Rotations.RotateBySpeed(self, container);
        };