diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 800a6a3..c6734b8 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -512,6 +512,7 @@ MonoBehaviour: PlayerFun: {fileID: 5050980832709922958} HandRetractSpeed: 10 HandRotationRetractSpeed: 300 + Bobbing: {fileID: 5620918083888341557} --- !u!114 &5050980832709922958 MonoBehaviour: m_ObjectHideFlags: 0 @@ -548,6 +549,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: BobbedTransform: {fileID: 4562179207922364650} + BobbingMultiplier: 1 BobbingGravity: 0.8 BobbingLaunchSpeed: 0.1 BobbingDirection: {x: 0, y: 1} diff --git a/Assets/Scripts/Effects/Bobbing.cs b/Assets/Scripts/Effects/Bobbing.cs index 584d9eb..8e86e9a 100644 --- a/Assets/Scripts/Effects/Bobbing.cs +++ b/Assets/Scripts/Effects/Bobbing.cs @@ -2,28 +2,30 @@ using System.Collections.Generic; using UnityEngine; -public class Bobbing : MonoBehaviour { +namespace Saltosion.OneWeapon.Effects { + public class Bobbing : MonoBehaviour { - public Transform BobbedTransform; + public Transform BobbedTransform; - [Range(0, 1)] - public float BobbingMultiplier = 1; - public float BobbingGravity = 0.5f; - public float BobbingLaunchSpeed = 5f; - public Vector2 BobbingDirection = new Vector2(0, 1); + [Range(0, 1)] + public float BobbingMultiplier = 1; + public float BobbingGravity = 0.5f; + public float BobbingLaunchSpeed = 5f; + public Vector2 BobbingDirection = new Vector2(0, 1); - private float BobbingSpeed; + private float BobbingSpeed; - private float CurrentBobbingState = 0; + private float CurrentBobbingState = 0; + + void Update() { + BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime); + if (CurrentBobbingState <= 0) { + BobbingSpeed = (BobbingLaunchSpeed / 10); + } + CurrentBobbingState += BobbingSpeed; + + BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier; - void Update() { - BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime); - if (CurrentBobbingState <= 0) { - BobbingSpeed = (BobbingLaunchSpeed / 10); } - CurrentBobbingState += BobbingSpeed; - - BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier; - } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs index 87d80e8..5449af2 100644 --- a/Assets/Scripts/Player/Player.cs +++ b/Assets/Scripts/Player/Player.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Animations; +using Saltosion.OneWeapon.Effects; namespace Saltosion.OneWeapon { public class Player : MonoBehaviour { @@ -36,6 +37,8 @@ namespace Saltosion.OneWeapon { private float CurrentHandRotation = 0f; private float CurrentHandDistance = 0f; + public Bobbing Bobbing; + public bool IsMoving { private set; get; } = false; @@ -96,10 +99,12 @@ namespace Saltosion.OneWeapon { BodyAnim.SetFloat("Speed", 1); HeadAnim.SetFloat("Speed", 1); IsMoving = true; + Bobbing.BobbingMultiplier = 1; } else { BodyAnim.SetFloat("Speed", 0); HeadAnim.SetFloat("Speed", 0); IsMoving = false; + Bobbing.BobbingMultiplier = 0; } bool Shoot = Input.GetButtonDown("Shoot");