Exemple #1
0
    private void StrafeTarget()
    {
        if (AttackTarget == null)
        {
            return;
        }

        if (strafeState == StrafeState.Strafing)
        {
            Throttle = .8f;

            bool shouldExtend = AttackTarget.DistanceFromAllColliders(ownTarget.Position) < 200f;
            if (shouldExtend)
            {
                extendPosition = ownTarget.Up * 1000f + AttackTarget.Position;
                strafeState    = StrafeState.Extending;
                IsFiring       = false;
            }
            else
            {
                var attackPoint = AttackTarget.GetLocalToWorldPoint(strafeTargetOffset);
                attackPoint = GunMaths.ComputeGunLead(
                    attackPoint,
                    AttackTarget.Velocity,
                    ownTarget.Position,
                    Vector3.zero,
                    ownShip.Specs.Weapons.MuzzleVelocity);

                TurnTowards(AttackTarget.Transform.TransformPoint(strafeTargetOffset));

                // Fire when within parameters.
                var angleToAttack    = Vector3.Angle(ownTarget.Forward, attackPoint - ownTarget.Position);
                var distanceToAttack = Vector3.Distance(attackPoint, ownTarget.Position);
                IsFiring = angleToAttack < 5f && distanceToAttack < 500f;
            }
        }
        else
        {
            Throttle = 1f;
            IsFiring = false;

            var distanceToExtend = Vector3.Distance(extendPosition, ownTarget.Position);
            if (distanceToExtend < 100f)
            {
                strafeState        = StrafeState.Strafing;
                strafeTargetOffset = AttackTarget.GetRandomPointOnTarget();
            }
            else
            {
                TurnTowards(extendPosition);
            }
        }
    }
    public static BaseState CreateBaseState(EnemyAIStateType stateType, EnemyMovement controller)
    {
        BaseState returnState = null;

        switch (stateType)
        {
        case EnemyAIStateType.AvoidBullet:
            returnState = new AvoidBulletState(controller);
            break;

        case EnemyAIStateType.Search:
            returnState = new SearchState(controller);
            break;

        case EnemyAIStateType.Strafe:
            returnState = new StrafeState(controller);
            break;
        }
        return(returnState);
    }