Beispiel #1
0
 private void RotateBulletToNewDirectionIfNeeded(BulletTriggerEffect effect, Vector2 direction)
 {
     // If we need to rotate the bullet to it's flying direction
     if (effect.RotateToNewDirection)
     {
         RotateBulletToNewDirection(direction);
     }
 }
Beispiel #2
0
    private void ApplyDirectionalEffects(BulletTriggerEffect effect)
    {
        float speed = (Velocity.magnitude);

        Vector2 direction = GetNewDirectionForBullet(effect);

        Velocity = speed * direction;

        RotateBulletToNewDirectionIfNeeded(effect, direction);
    }
Beispiel #3
0
    private void ApplyEffects(BulletTriggerEffect effect)
    {
        // Change the acceleration if we need to.
        if (effect.applyAcceleration)
        {
            AccelerationSpeed = effect.triggerAcceleration;
        }

        if (effect.applyRotationalAcceleration)
        {
            RotationAccelerationSpeed = effect.triggerRotationalAcceleration;
        }

        if (effect.applyRotation)
        {
            RotationSpeed = effect.triggerRotationSpeed;
        }

        ApplySpeedAndDirectionByEffect(effect);
    }
Beispiel #4
0
    private Vector2 GetNewDirectionForBullet(BulletTriggerEffect effect)
    {
        Vector2 direction;

        // If we need to make the bullet fly towards the player.
        if (effect.DirectionTargetPlayer)
        {
            var target = Player.Instance.transform;

            // Find out how much this bullet would have to rotate.
            Quaternion rotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up);

            direction = (target.position - transform.position).normalized;
        }
        else
        {
            direction = effect.NewDirection.normalized;
        }

        return(direction);
    }
Beispiel #5
0
    private void ApplySpeedAndDirectionByEffect(BulletTriggerEffect effect)
    {
        // If we need to change both the speed and the direction.
        if (effect.applySpeed && effect.changeDirection)
        {
            // Apply both at once.
            float   speed     = effect.triggeredSpeed;
            Vector2 direction = GetNewDirectionForBullet(effect);
            Velocity = speed * direction;

            RotateBulletToNewDirectionIfNeeded(effect, direction);
        }
        else if (effect.applySpeed)
        {
            // Apply speed only.
            Velocity = Velocity.normalized * effect.triggeredSpeed;
        }
        else if (effect.changeDirection)
        {
            // Change direction only.
            ApplyDirectionalEffects(effect);
        }
    }