diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index d2a486f..1497239 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -424,6 +424,7 @@ GameObject: - component: {fileID: 412028545510300634} - component: {fileID: 8489029732530782806} - component: {fileID: 5050980832709922958} + - component: {fileID: 7263640616704110489} - component: {fileID: 5620918083888341557} m_Layer: 0 m_Name: Player @@ -499,7 +500,7 @@ MonoBehaviour: Body: {fileID: 8489029732530782792} Hand: {fileID: 8334477035414792174} SubHand: {fileID: 340836170559364036} - MoveSpeed: 50 + Movement: {fileID: 7263640616704110489} BodySprite: {fileID: 8489029732241002784} BodyAnim: {fileID: 7470056256336689202} HeadSprite: {fileID: 8489029732599905344} @@ -512,7 +513,6 @@ MonoBehaviour: PlayerFun: {fileID: 5050980832709922958} HandRetractSpeed: 10 HandRotationRetractSpeed: 300 - Bobbing: {fileID: 5620918083888341557} --- !u!114 &5050980832709922958 MonoBehaviour: m_ObjectHideFlags: 0 @@ -536,6 +536,23 @@ MonoBehaviour: DebugAdd10Fun: 0 DebugSubtract10Fun: 0 GodMode: 0 +--- !u!114 &7263640616704110489 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8489029732530782804} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3} + m_Name: + m_EditorClassIdentifier: + Body: {fileID: 8489029732530782792} + Bobbing: {fileID: 5620918083888341557} + Direction: {x: 0, y: 0} + MaxSpeed: 7 + AccelerationSpeed: 70 --- !u!114 &5620918083888341557 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/AI/Triggers/EnemySighted.cs b/Assets/Scripts/AI/Triggers/EnemySighted.cs index d5b18f6..fa1eb83 100644 --- a/Assets/Scripts/AI/Triggers/EnemySighted.cs +++ b/Assets/Scripts/AI/Triggers/EnemySighted.cs @@ -1,4 +1,5 @@ using UnityEngine; +using Saltosion.OneWeapon.Utils; namespace Saltosion.OneWeapon.AI.Triggers { public class EnemySighted : Trigger { diff --git a/Assets/Scripts/AI/Triggers/PlayerSighted.cs b/Assets/Scripts/AI/Triggers/PlayerSighted.cs index f87e63d..5805f34 100644 --- a/Assets/Scripts/AI/Triggers/PlayerSighted.cs +++ b/Assets/Scripts/AI/Triggers/PlayerSighted.cs @@ -1,4 +1,5 @@ using UnityEngine; +using Saltosion.OneWeapon.Utils; namespace Saltosion.OneWeapon.AI.Triggers { public class PlayerSighted : Trigger { diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs index 5449af2..738062b 100644 --- a/Assets/Scripts/Player/Player.cs +++ b/Assets/Scripts/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Animations; using Saltosion.OneWeapon.Effects; +using Saltosion.OneWeapon.Utils; namespace Saltosion.OneWeapon { public class Player : MonoBehaviour { @@ -10,7 +11,8 @@ namespace Saltosion.OneWeapon { public Rigidbody2D Body; public Transform Hand; public Transform SubHand; - public float MoveSpeed = 50f; + + public AcceleratedMovement Movement; public SpriteRenderer BodySprite; public Animator BodyAnim; @@ -37,7 +39,6 @@ namespace Saltosion.OneWeapon { private float CurrentHandRotation = 0f; private float CurrentHandDistance = 0f; - public Bobbing Bobbing; public bool IsMoving { private set; get; @@ -47,9 +48,7 @@ namespace Saltosion.OneWeapon { float X = Input.GetAxis("Horizontal"); float Y = Input.GetAxis("Vertical"); - Vector2 Direction = new Vector2(X, Y).normalized; - - Body.velocity = Direction * MoveSpeed; + Movement.Direction = new Vector2(X, Y).normalized; Vector3 MousePos = Input.mousePosition; Vector3 PointedPos = Camera.main.ScreenToWorldPoint(MousePos); @@ -95,17 +94,13 @@ namespace Saltosion.OneWeapon { } - if (Direction.magnitude > 0.05) { - BodyAnim.SetFloat("Speed", 1); - HeadAnim.SetFloat("Speed", 1); + if (Movement.SpeedPercentage > 0.05) { IsMoving = true; - Bobbing.BobbingMultiplier = 1; } else { - BodyAnim.SetFloat("Speed", 0); - HeadAnim.SetFloat("Speed", 0); IsMoving = false; - Bobbing.BobbingMultiplier = 0; } + BodyAnim.SetFloat("Speed", Movement.SpeedPercentage); + HeadAnim.SetFloat("Speed", Movement.SpeedPercentage); bool Shoot = Input.GetButtonDown("Shoot"); if (Shoot) { diff --git a/Assets/Scripts/Util.meta b/Assets/Scripts/Utils.meta similarity index 77% rename from Assets/Scripts/Util.meta rename to Assets/Scripts/Utils.meta index 7951603..558bb82 100644 --- a/Assets/Scripts/Util.meta +++ b/Assets/Scripts/Utils.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 018a3d1f7d59172409fca8ec15f1c654 +guid: 1444582c6b6fb0541bbe54879e9a5012 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Utils/AcceleratedMovement.cs b/Assets/Scripts/Utils/AcceleratedMovement.cs new file mode 100644 index 0000000..1abbf55 --- /dev/null +++ b/Assets/Scripts/Utils/AcceleratedMovement.cs @@ -0,0 +1,39 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Saltosion.OneWeapon.Effects; + +namespace Saltosion.OneWeapon.Utils { + public class AcceleratedMovement : MonoBehaviour { + + public Rigidbody2D Body; + public Bobbing Bobbing; + + private Vector2 LastDirection = Vector2.zero; + public Vector2 Direction = Vector2.zero; + public float MaxSpeed = 50; + public float AccelerationSpeed = 35; + + public Vector2 CurrentVelocity { private set; get; } + public float SpeedPercentage { private set; get; } + private float CurrentSpeed = 0; + + void Update() { + if (Direction.magnitude > 0) { + CurrentSpeed += AccelerationSpeed * Time.deltaTime; + } else { + CurrentSpeed -= AccelerationSpeed * Time.deltaTime; + } + CurrentSpeed *= 1 - (Vector2.Angle(Direction, LastDirection) / 180); + Debug.Log(1 - (Vector2.Angle(Direction, LastDirection) / 180)); + CurrentSpeed = Mathf.Clamp(CurrentSpeed, 0, MaxSpeed); + SpeedPercentage = CurrentSpeed / MaxSpeed; + + CurrentVelocity = Direction.normalized * CurrentSpeed; + + LastDirection = Direction; + Body.velocity = CurrentVelocity; + Bobbing.BobbingMultiplier = SpeedPercentage; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/AcceleratedMovement.cs.meta b/Assets/Scripts/Utils/AcceleratedMovement.cs.meta new file mode 100644 index 0000000..de102f4 --- /dev/null +++ b/Assets/Scripts/Utils/AcceleratedMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ba61752571d0d70478c63122f73914db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Util/CameraHelper.cs b/Assets/Scripts/Utils/CameraHelper.cs similarity index 100% rename from Assets/Scripts/Util/CameraHelper.cs rename to Assets/Scripts/Utils/CameraHelper.cs diff --git a/Assets/Scripts/Util/CameraHelper.cs.meta b/Assets/Scripts/Utils/CameraHelper.cs.meta similarity index 100% rename from Assets/Scripts/Util/CameraHelper.cs.meta rename to Assets/Scripts/Utils/CameraHelper.cs.meta diff --git a/Assets/Scripts/Util/Options.cs b/Assets/Scripts/Utils/Options.cs similarity index 100% rename from Assets/Scripts/Util/Options.cs rename to Assets/Scripts/Utils/Options.cs diff --git a/Assets/Scripts/Util/Options.cs.meta b/Assets/Scripts/Utils/Options.cs.meta similarity index 100% rename from Assets/Scripts/Util/Options.cs.meta rename to Assets/Scripts/Utils/Options.cs.meta diff --git a/Assets/Scripts/Util/Util.cs b/Assets/Scripts/Utils/Util.cs similarity index 97% rename from Assets/Scripts/Util/Util.cs rename to Assets/Scripts/Utils/Util.cs index 5d857ed..d91281e 100644 --- a/Assets/Scripts/Util/Util.cs +++ b/Assets/Scripts/Utils/Util.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace Saltosion.OneWeapon { +namespace Saltosion.OneWeapon.Utils { public class Util { public static T GetClosestTo(Transform Searcher, float radius, bool needsLineOfSight = false) where T : MonoBehaviour { Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(Searcher.position, radius); diff --git a/Assets/Scripts/Util/Util.cs.meta b/Assets/Scripts/Utils/Util.cs.meta similarity index 100% rename from Assets/Scripts/Util/Util.cs.meta rename to Assets/Scripts/Utils/Util.cs.meta