private void RotateBulletToNewDirectionIfNeeded(BulletTriggerEffect effect, Vector2 direction) { // If we need to rotate the bullet to it's flying direction if (effect.RotateToNewDirection) { RotateBulletToNewDirection(direction); } }
private void ApplyDirectionalEffects(BulletTriggerEffect effect) { float speed = (Velocity.magnitude); Vector2 direction = GetNewDirectionForBullet(effect); Velocity = speed * direction; RotateBulletToNewDirectionIfNeeded(effect, direction); }
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); }
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); }
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); } }