From 3ad9042702ac55da78ccf5fb23a9562867da7e6f Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 3 Feb 2024 21:35:06 +0100 Subject: [PATCH 1/3] Seperated keyboard movement --- .../Scripts/Player/PlayerAnimationHandler.cs | 2 +- Assets/Scripts/Player/PlayerInput.cs | 16 ++++-- Assets/Scripts/Player/PlayerMovement.cs | 5 ++ ProjectSettings/EditorBuildSettings.asset | 3 +- ProjectSettings/InputManager.asset | 53 +++++++++++++++---- 5 files changed, 64 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Player/PlayerAnimationHandler.cs b/Assets/Scripts/Player/PlayerAnimationHandler.cs index ef54b41..f26e30f 100644 --- a/Assets/Scripts/Player/PlayerAnimationHandler.cs +++ b/Assets/Scripts/Player/PlayerAnimationHandler.cs @@ -27,7 +27,7 @@ public class PlayerAnimationHandler : MonoBehaviour } prevPos = transform.position; - } + } public void Idle() { diff --git a/Assets/Scripts/Player/PlayerInput.cs b/Assets/Scripts/Player/PlayerInput.cs index 3497fea..7721fc9 100644 --- a/Assets/Scripts/Player/PlayerInput.cs +++ b/Assets/Scripts/Player/PlayerInput.cs @@ -17,6 +17,8 @@ public class PlayerInput : MonoBehaviour public event Action ropeLengthShrinken; public event Action ropeLengthExtend; + public bool useArrowKeys = false; + public int PlayerNum => playerNumber; private void Start() @@ -45,11 +47,19 @@ public class PlayerInput : MonoBehaviour } else { - movement.x = Input.GetAxisRaw("Horizontal"); - movement.y = Input.GetAxisRaw("Vertical"); + if (!useArrowKeys) + { + movement.x = Input.GetAxisRaw("bruh"); + movement.y = Input.GetAxisRaw("bruh_v"); + } + else + { + movement.x = Input.GetAxisRaw("bruh2"); + movement.y = Input.GetAxisRaw("bruh2_v"); + } whipAttack = Input.GetKey(KeyCode.B); + //Debug.Log($"player {playerNumber}: move {movement}"); } - //Debug.Log($"player {playerNumber}: move {movement}"); } } diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index ff91a14..91247a5 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -35,6 +35,11 @@ public class PlayerMovement : MonoBehaviour rb = GetComponent(); playerInput = GetComponent(); + if (gameObject.name == "Player2") + { + playerInput.useArrowKeys = true; + } + StartCoroutine(ToggleWithDelay()); } diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index a020a0d..63fa704 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -11,4 +11,5 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/GameScene.unity guid: 0400e5e5779425c40ba3164b1e0b5b59 - m_configObjects: {} + m_configObjects: + com.unity.input.settings: {fileID: 11400000, guid: de04e34f85a966e4da851d9b3d804fa1, type: 2} diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index b16147e..8d07924 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -150,11 +150,11 @@ InputManager: axis: 2 joyNum: 0 - serializedVersion: 3 - m_Name: Horizontal + m_Name: bruh descriptiveName: descriptiveNegativeName: - negativeButton: - positiveButton: + negativeButton: a + positiveButton: d altNegativeButton: altPositiveButton: gravity: 0 @@ -162,11 +162,11 @@ InputManager: sensitivity: 1 snap: 0 invert: 0 - type: 2 - axis: 0 - joyNum: 0 + type: 0 + axis: 15 + joyNum: 6 - serializedVersion: 3 - m_Name: Vertical + m_Name: bruh_v descriptiveName: descriptiveNegativeName: negativeButton: @@ -178,9 +178,9 @@ InputManager: sensitivity: 1 snap: 0 invert: 1 - type: 2 - axis: 1 - joyNum: 0 + type: 0 + axis: 15 + joyNum: 8 - serializedVersion: 3 m_Name: Fire1 descriptiveName: @@ -485,3 +485,36 @@ InputManager: type: 2 axis: 5 joyNum: 0 + - serializedVersion: 3 + m_Name: bruh2 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: + altPositiveButton: + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 27 + joyNum: 10 + - serializedVersion: 3 + m_Name: bruh2_v + descriptiveName: + descriptiveNegativeName: + negativeButton: down + positiveButton: up + altNegativeButton: + altPositiveButton: + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 5 + joyNum: 8 + m_UsePhysicalKeys: 1 From 62afc25653ca66cb177d5984420265af8b4079c0 Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sat, 3 Feb 2024 12:38:42 -0800 Subject: [PATCH 2/3] zhen zync --- Assets/Resources/Player1.prefab | 1 + Assets/Resources/Player2.prefab | 1 + Assets/Scripts/Player/PlayerMovement.cs | 3 ++- Assets/Scripts/Rope/RopeSimulator.cs | 5 ++++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Assets/Resources/Player1.prefab b/Assets/Resources/Player1.prefab index 27feb4a..d7d06c0 100644 --- a/Assets/Resources/Player1.prefab +++ b/Assets/Resources/Player1.prefab @@ -225,6 +225,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3dbdb849a2f5df14d9e109a7776c5ac0, type: 3} m_Name: m_EditorClassIdentifier: + animationHandler: {fileID: 3878447480781341932} moveSpeed: 70 stepCooldown: 0.2 stepVibrationTime: 0.05 diff --git a/Assets/Resources/Player2.prefab b/Assets/Resources/Player2.prefab index 2c95419..d24e8e4 100644 --- a/Assets/Resources/Player2.prefab +++ b/Assets/Resources/Player2.prefab @@ -225,6 +225,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3dbdb849a2f5df14d9e109a7776c5ac0, type: 3} m_Name: m_EditorClassIdentifier: + animationHandler: {fileID: 3878447480781341932} moveSpeed: 65 stepCooldown: 0.2 stepVibrationTime: 0.05 diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 91247a5..621fc97 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -7,6 +7,7 @@ using System.Linq; [RequireComponent(typeof(PlayerInput))] public class PlayerMovement : MonoBehaviour { + public PlayerAnimationHandler animationHandler; public float moveSpeed = 5f; private Rigidbody2D rb; @@ -48,7 +49,7 @@ public class PlayerMovement : MonoBehaviour if (playerInput.movement != Vector2.zero) { RumbleWalk(); - GetComponent().Run(); + animationHandler.Run(); } } private void FixedUpdate() diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index 01a8948..a1a38d9 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -263,7 +263,10 @@ public class RopeSimulator : MonoBehaviour // Handle squeze kills foreach (var collider in colliderToSquezeForce) { - ISquezeDamageReceiver squezeDamageReceiver = collider.Key.GetComponent(); + ISquezeDamageReceiver squezeDamageReceiver = collider.Key.transform.root.GetComponent(); + if (squezeDamageReceiver == null) + squezeDamageReceiver = collider.Key.GetComponent(); + if (squezeDamageReceiver == null) continue; squezeDamageReceiver.TakeSquezeDamage(collider.Value * squezeDamage); From b2da2e48b3424c9882c8cf112c3e2e8b8c4962e0 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 3 Feb 2024 21:44:51 +0100 Subject: [PATCH 3/3] Added sprite flipping by movement script --- Assets/Resources/Player1.prefab | 14 ++++++++++ Assets/Resources/Player2.prefab | 14 ++++++++++ .../Scripts/Player/PlayerAnimationHandler.cs | 18 ------------- .../Scripts/Player/SpriteMovementFlipper.cs | 27 +++++++++++++++++++ .../Player/SpriteMovementFlipper.cs.meta | 11 ++++++++ 5 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 Assets/Scripts/Player/SpriteMovementFlipper.cs create mode 100644 Assets/Scripts/Player/SpriteMovementFlipper.cs.meta diff --git a/Assets/Resources/Player1.prefab b/Assets/Resources/Player1.prefab index 27feb4a..15b17ad 100644 --- a/Assets/Resources/Player1.prefab +++ b/Assets/Resources/Player1.prefab @@ -189,6 +189,7 @@ GameObject: - component: {fileID: 3878447480781341932} - component: {fileID: 1749848915408613053} - component: {fileID: 1949941092232239315} + - component: {fileID: 5302021185317648001} m_Layer: 7 m_Name: Player1 m_TagString: Player @@ -341,3 +342,16 @@ MonoBehaviour: movement: {x: 0, y: 0} look: {x: 0, y: 0} whipAttack: 0 + useArrowKeys: 0 +--- !u!114 &5302021185317648001 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3120938410244321186} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c66441ada081b6c4c841000e83cc2b7a, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Resources/Player2.prefab b/Assets/Resources/Player2.prefab index 2c95419..1e77040 100644 --- a/Assets/Resources/Player2.prefab +++ b/Assets/Resources/Player2.prefab @@ -189,6 +189,7 @@ GameObject: - component: {fileID: 3878447480781341932} - component: {fileID: 7071433868121438663} - component: {fileID: 1949941092232239315} + - component: {fileID: 4751086095402136128} m_Layer: 7 m_Name: Player2 m_TagString: Player @@ -341,3 +342,16 @@ MonoBehaviour: movement: {x: 0, y: 0} look: {x: 0, y: 0} whipAttack: 0 + useArrowKeys: 0 +--- !u!114 &4751086095402136128 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3120938410244321186} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c66441ada081b6c4c841000e83cc2b7a, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scripts/Player/PlayerAnimationHandler.cs b/Assets/Scripts/Player/PlayerAnimationHandler.cs index f26e30f..13a8fa5 100644 --- a/Assets/Scripts/Player/PlayerAnimationHandler.cs +++ b/Assets/Scripts/Player/PlayerAnimationHandler.cs @@ -5,30 +5,12 @@ using UnityEngine; public class PlayerAnimationHandler : MonoBehaviour { Animator animator; - SpriteRenderer sp; - - Vector3 prevPos; void Start() { animator = GetComponentInChildren(); - sp = GetComponentInChildren(); } - private void Update() - { - if ((transform.position - prevPos).x > 0.1f) - { - sp.flipX = false; - } - else if ((transform.position - prevPos).x < -0.1f) - { - sp.flipX = true; - } - - prevPos = transform.position; - } - public void Idle() { animator.SetTrigger("Idle"); diff --git a/Assets/Scripts/Player/SpriteMovementFlipper.cs b/Assets/Scripts/Player/SpriteMovementFlipper.cs new file mode 100644 index 0000000..cf33f64 --- /dev/null +++ b/Assets/Scripts/Player/SpriteMovementFlipper.cs @@ -0,0 +1,27 @@ +using UnityEngine; + +public class SpriteMovementFlipper : MonoBehaviour +{ + SpriteRenderer sp; + + Vector3 prevPos; + + void Start() + { + sp = GetComponentInChildren(); + } + + private void Update() + { + if ((transform.position - prevPos).x > 0.1f) + { + sp.flipX = false; + } + else if ((transform.position - prevPos).x < -0.1f) + { + sp.flipX = true; + } + + prevPos = transform.position; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player/SpriteMovementFlipper.cs.meta b/Assets/Scripts/Player/SpriteMovementFlipper.cs.meta new file mode 100644 index 0000000..c555aef --- /dev/null +++ b/Assets/Scripts/Player/SpriteMovementFlipper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c66441ada081b6c4c841000e83cc2b7a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: