2019-08-07 21:25:39 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
namespace Saltosion.OneWeapon.Effects {
|
|
|
|
|
public class Bobbing : MonoBehaviour {
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
public Transform BobbedTransform;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
[Range(0, 1)]
|
|
|
|
|
public float BobbingMultiplier = 1;
|
2019-08-14 16:48:17 +02:00
|
|
|
|
public float BobbingGravity = 0.8f;
|
|
|
|
|
public float BobbingLaunchSpeed = 0.12f;
|
2019-08-07 22:06:51 +02:00
|
|
|
|
|
|
|
|
|
public float BobbingFrequency = 0;
|
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
public Vector2 BobbingDirection = new Vector2(0, 1);
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
private float BobbingSpeed;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
private float CurrentBobbingState = 0;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
void Update() {
|
2019-08-07 22:06:51 +02:00
|
|
|
|
BobbingFrequency = (BobbingLaunchSpeed * 2) / BobbingGravity;
|
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime);
|
|
|
|
|
if (CurrentBobbingState <= 0) {
|
|
|
|
|
BobbingSpeed = (BobbingLaunchSpeed / 10);
|
|
|
|
|
}
|
2019-08-07 22:06:51 +02:00
|
|
|
|
CurrentBobbingState += BobbingSpeed * BobbingMultiplier;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
2019-08-07 21:43:22 +02:00
|
|
|
|
}
|
2019-08-07 21:25:39 +02:00
|
|
|
|
}
|
2019-08-07 21:43:22 +02:00
|
|
|
|
}
|