BloodAndGore/Assets/Scripts/Effects/Bobbing.cs

36 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Saltosion.OneWeapon.Effects {
public class Bobbing : MonoBehaviour {
public Transform BobbedTransform;
[Range(0, 1)]
public float BobbingMultiplier = 1;
public float BobbingGravity = 0.5f;
public float BobbingLaunchSpeed = 5f;
public float BobbingFrequency = 0;
public Vector2 BobbingDirection = new Vector2(0, 1);
private float BobbingSpeed;
private float CurrentBobbingState = 0;
void Update() {
BobbingFrequency = (BobbingLaunchSpeed * 2) / BobbingGravity;
BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime);
if (CurrentBobbingState <= 0) {
BobbingSpeed = (BobbingLaunchSpeed / 10);
}
CurrentBobbingState += BobbingSpeed * BobbingMultiplier;
BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier;
}
}
}