From 5440c56426c3beaf985157fd66cec91c19fb2ad5 Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 00:11:01 -0400 Subject: [PATCH] Fixed throwing minions without direction --- Assets/Prefabs/Vampire.prefab | 4 ++++ Assets/Scripts/GameFlowManager.cs | 2 ++ Assets/Scripts/MinionThrower.cs | 20 ++++++++++++++------ Assets/Scripts/PlayerStats.cs | 3 +++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Assets/Prefabs/Vampire.prefab b/Assets/Prefabs/Vampire.prefab index 8d6c6b2..649b204 100644 --- a/Assets/Prefabs/Vampire.prefab +++ b/Assets/Prefabs/Vampire.prefab @@ -69,6 +69,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3d475633c5bc498fac5a9e5ead64da55, type: 3} m_Name: m_EditorClassIdentifier: + arena: {fileID: 0} gameFlowManager: {fileID: 0} k__BackingField: 100 healthBar: {fileID: 0} @@ -84,6 +85,7 @@ MonoBehaviour: deadColor: {r: 1, g: 0, b: 0, a: 1} emptyColor: {r: 1, g: 0, b: 0, a: 1} playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} + playerMovement: {fileID: 0} --- !u!114 &1967503440015794769 MonoBehaviour: m_ObjectHideFlags: 0 @@ -96,7 +98,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3} m_Name: m_EditorClassIdentifier: + arena: {fileID: 0} gameFlowManager: {fileID: 0} + playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} minionPrefabs: - {fileID: 2399377275812995974, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3} aimArrow: {fileID: 5124059627794595469} diff --git a/Assets/Scripts/GameFlowManager.cs b/Assets/Scripts/GameFlowManager.cs index 6acfff4..4f6ed1f 100644 --- a/Assets/Scripts/GameFlowManager.cs +++ b/Assets/Scripts/GameFlowManager.cs @@ -53,6 +53,8 @@ public class GameFlowManager : MonoBehaviour { if (CurrentState is StartFlowState) { startPrompt.SetActive(false); SwitchState(new GameplayFlowState(this)); + } else if (CurrentState is GameplayFlowState) { + SwitchState(new PauseMenuFlowState(this)); } } diff --git a/Assets/Scripts/MinionThrower.cs b/Assets/Scripts/MinionThrower.cs index cce0b3e..ca9bfb9 100644 --- a/Assets/Scripts/MinionThrower.cs +++ b/Assets/Scripts/MinionThrower.cs @@ -8,12 +8,14 @@ public class MinionThrower : MonoBehaviour { Arena arena = null!; [SerializeField] [Required] GameFlowManager gameFlowManager = null!; + [SerializeField] [Required] + PlayerStats playerStats = null!; public Entity[] minionPrefabs; public GameObject aimArrow; bool isInThrowMode; - Vector2 throwDirection = Vector2.right; + Vector2 throwDirection; MinionBar minionBar; VampireEntity vampireEntity; PlayerMovement movement; @@ -47,7 +49,7 @@ public class MinionThrower : MonoBehaviour { if (context.performed) { isInThrowMode = true; aimArrow.SetActive(true); - } else if (context.canceled) { + } else if (context.canceled && throwDirection.magnitude >= playerStats.MinJoystickValueForThrowing) { PerformThrow(); isInThrowMode = false; aimArrow.SetActive(false); @@ -58,7 +60,10 @@ public class MinionThrower : MonoBehaviour { if (!gameFlowManager.CanDoAction) return; - throwDirection = context.ReadValue().normalized; + throwDirection = context.ReadValue(); + if (throwDirection.sqrMagnitude > 1f) + throwDirection.Normalize(); + if (vampireEntity.playerMovement.facingRight) { aimArrow.transform.rotation = Quaternion.FromToRotation(Vector2.right, throwDirection); } else { @@ -84,13 +89,16 @@ public class MinionThrower : MonoBehaviour { var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, arena.minionParent) .GetComponent(); newMinion.arena = arena; - newMinion.transform.position = transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f; - newMinion.direction = throwDirection; + if (throwDirection == Vector2.zero) + Debug.LogWarning("Throwing with a null throwDirection."); + Vector2 normalizedDirection = throwDirection.normalized; + newMinion.transform.position = transform.position + (Vector3)normalizedDirection; + newMinion.direction = normalizedDirection; newMinion.gameFlowManager = vampireEntity.gameFlowManager; if (movement.GetSafeZoneIfImmobile() is { } safeZone) { newMinion.thrownFromSafeZone = true; - newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection); + newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(normalizedDirection); } } diff --git a/Assets/Scripts/PlayerStats.cs b/Assets/Scripts/PlayerStats.cs index 6729398..82c69b0 100644 --- a/Assets/Scripts/PlayerStats.cs +++ b/Assets/Scripts/PlayerStats.cs @@ -10,4 +10,7 @@ public class PlayerStats : ScriptableObject { [field: SerializeField] [Min(0f)] public float bloodLossRate = 1f; + + [field: SerializeField] [field: Range(0f, 1f)] + public float MinJoystickValueForThrowing { get; private set; } = .4f; } \ No newline at end of file