Exemplo n.º 1
0
    public override void SwarmlingAttackRuleCalculation()
    {
        if (DoNotMove)
        {
            return;
        }

        if (ClosestPlayer && ClosestPlayerSqrDistance < Mathf.Pow(AttackDistance, 2))
        {
            // Attack if player is really close, or if AttackDelayCounter is reached and Player is moving in the Beetles direction.
            if ((ClosestPlayerSqrDistance <= 4) ||
                (AttackDelayCounter <= 0 && (ClosestPlayerSqrDistance < ((ClosestPlayer.transform.position - SwarmlingTransform.position).sqrMagnitude))))    //ClosestPlayerSqrDistance < ((ClosestPlayer.transform.position + ClosestPlayer.GetTargetVelocity()) - SwarmlingTransform.position).sqrMagnitude)     //&& (Vector3.Dot(ClosestPlayer.GetTargetVelocity(), (ClosestPlayer.transform.position - transform.position).normalized) < AttackAngle))
            {
                DoNotMove = true;

                ThisSwarmlingCharacter.SwarmlingStartSkillActivation();

                SwarmlingTransform.rotation = Quaternion.LookRotation(ClosestPlayer.transform.position - SwarmlingTransform.position);

                NMAgent.avoidancePriority = 40;
            }
            else
            {
                AttackDelayCounter = Mathf.Max(AttackDelayCounter - UpdateTimer, 0);
            }
        }
        else
        {
            AttackDelayCounter = Mathf.Min(AttackDelayCounter + UpdateTimer, AttackDelayTimeMax);
        }
    }
Exemplo n.º 2
0
    public override void SwarmlingAttackRuleCalculation()
    {
        if (!DoNotMove && !ScaredOfPlayer && ClosestPlayer && ClosestPlayerSqrDistance < Mathf.Pow(AttackDistance, 2))
        {
            DoNotMove = true;

            ThisSwarmlingCharacter.SwarmlingStartSkillActivation();

            SwarmlingTransform.rotation = Quaternion.LookRotation(ClosestPlayer.transform.position - SwarmlingTransform.position);

            NMAgent.avoidancePriority = 40;
        }
    }
Exemplo n.º 3
0
    // This is updated every frame (required, as movement is done through this):
    private void UpdateWingAttack()
    {
        // Check if normal Movement is allowed (= not currently attacking):
        if (!DoNotMove)
        {
            // Count down Attack Cooldown:
            if (AttackCooldownCounter > 0)
            {
                AttackCooldownCounter -= Time.deltaTime;
            }
            return;
        }

        // Count down the Observation Time:
        if (TargetSearchTimeCounter > 0)
        {
            TargetSearchTimeCounter -= Time.deltaTime;

            SwarmlingBodyTransform.rotation = Quaternion.Slerp(SwarmlingBodyTransform.rotation, Quaternion.LookRotation(SwarmlingBodyTransform.position - ClosestPlayer.transform.position), 5f * Time.deltaTime);

            if (TargetSearchTimeCounter <= 0)
            {
                //DoNotMove = true;

                //ThisSwarmlingCharacter.SwarmlingStartSkillActivation();

                SwarmlingTransform.rotation = Quaternion.LookRotation(ClosestPlayer.transform.position - SwarmlingTransform.position);

                NMAgent.enabled = false;

                ThisSwarmlingCharacter.StartAnimation(AnimFlyUp, SwarmlingFlightUpwardsTimeEnd, 0);

                AttackCooldownCounter = AttackCooldown; // Cooldown only starts counting down if !DoNotMove / Another Attack could be started.
            }

            return;
        }

        SwarmlingFlightCounter += Time.deltaTime;

        if (SwarmlingFlightCounter <= SwarmlingFlightUpwardsTimeEnd)
        {
            SwarmlingBodyTransform.position += Vector3.up * SwarmlingFlightUpwardsSpeed * Time.deltaTime;
            //SwarmlingTransform.rotation = Quaternion.LookRotation(ClosestPlayer.transform.position - SwarmlingTransform.position);

            SwarmlingBodyTransform.rotation = Quaternion.Slerp(SwarmlingBodyTransform.rotation, Quaternion.LookRotation(SwarmlingBodyTransform.position - ClosestPlayer.transform.position), 5f * Time.deltaTime);
        }
        else if (SwarmlingFlightTowardsCounter <= 1)
        {
            if (!TargetPointCalculated)
            {
                TargetPointCalculated = true;
                TargetPoint           = ClosestPlayer.transform.position; // - SwarmlingBodyTransform.position;
                StartingPoint         = SwarmlingBodyTransform.position;
                ThisSwarmlingCharacter.StartAnimation(AnimFly, 1, 0);
                //TargetPoint = TargetPoint.normalized * SwarmlingFlightTowardsTargetSpeed;
                //FlyingVector = TargetPoint - StartingPoint;
                //FlyingTime = Vector3.Distance(StartingPoint, TargetPoint) / SwarmlingFlightTowardsTargetSpeed;
                //FlyingPosition = SwarmlingBodyTransform.position;

                //SwarmlingTransform.rotation = Quaternion.LookRotation(ClosestPlayer.transform.position - SwarmlingTransform.position);
            }

            SwarmlingFlightTowardsCounter += Time.deltaTime * SwarmlingFlightTowardsTargetSpeed;

            //SwarmlingBodyTransform.position = Vector3.Lerp(StartingPoint, TargetPoint, SwarmlingFlightTowardsCounter);

            //FlyingPosition = Vector3.MoveTowards(FlyingPosition, TargetPoint, Time.deltaTime * SwarmlingFlightTowardsTargetSpeed);

            SwarmlingBodyTransform.position  = Vector3.Lerp(StartingPoint, TargetPoint, SwarmlingFlightTowardsCounter);
            SwarmlingBodyTransform.position += Vector3.up * Mathf.Sin((SwarmlingFlightTowardsCounter) * Mathf.PI) * 2;

            // Debug.Log("SIN: " + Mathf.Sin(SwarmlingFlightTowardsCounter * Mathf.PI) + " at: " + SwarmlingFlightTowardsCounter);
        }
        else if (!HasAttacked)
        {
            HasAttacked = true;
            ThisSwarmlingCharacter.SwarmlingStartSkillActivation();
        }
    }