Fixed throwing minions without direction

This commit is contained in:
Jason Durand 01 2022-04-03 00:11:01 -04:00
parent 5545e42e5a
commit 5440c56426
4 changed files with 23 additions and 6 deletions

View File

@ -69,6 +69,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3d475633c5bc498fac5a9e5ead64da55, type: 3} m_Script: {fileID: 11500000, guid: 3d475633c5bc498fac5a9e5ead64da55, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
arena: {fileID: 0}
gameFlowManager: {fileID: 0} gameFlowManager: {fileID: 0}
<Health>k__BackingField: 100 <Health>k__BackingField: 100
healthBar: {fileID: 0} healthBar: {fileID: 0}
@ -84,6 +85,7 @@ MonoBehaviour:
deadColor: {r: 1, g: 0, b: 0, a: 1} deadColor: {r: 1, g: 0, b: 0, a: 1}
emptyColor: {r: 1, g: 0, b: 0, a: 1} emptyColor: {r: 1, g: 0, b: 0, a: 1}
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
playerMovement: {fileID: 0}
--- !u!114 &1967503440015794769 --- !u!114 &1967503440015794769
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -96,7 +98,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3} m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
arena: {fileID: 0}
gameFlowManager: {fileID: 0} gameFlowManager: {fileID: 0}
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
minionPrefabs: minionPrefabs:
- {fileID: 2399377275812995974, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3} - {fileID: 2399377275812995974, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
aimArrow: {fileID: 5124059627794595469} aimArrow: {fileID: 5124059627794595469}

View File

@ -53,6 +53,8 @@ public class GameFlowManager : MonoBehaviour {
if (CurrentState is StartFlowState) { if (CurrentState is StartFlowState) {
startPrompt.SetActive(false); startPrompt.SetActive(false);
SwitchState(new GameplayFlowState(this)); SwitchState(new GameplayFlowState(this));
} else if (CurrentState is GameplayFlowState) {
SwitchState(new PauseMenuFlowState(this));
} }
} }

View File

@ -8,12 +8,14 @@ public class MinionThrower : MonoBehaviour {
Arena arena = null!; Arena arena = null!;
[SerializeField] [Required] [SerializeField] [Required]
GameFlowManager gameFlowManager = null!; GameFlowManager gameFlowManager = null!;
[SerializeField] [Required]
PlayerStats playerStats = null!;
public Entity[] minionPrefabs; public Entity[] minionPrefabs;
public GameObject aimArrow; public GameObject aimArrow;
bool isInThrowMode; bool isInThrowMode;
Vector2 throwDirection = Vector2.right; Vector2 throwDirection;
MinionBar minionBar; MinionBar minionBar;
VampireEntity vampireEntity; VampireEntity vampireEntity;
PlayerMovement movement; PlayerMovement movement;
@ -47,7 +49,7 @@ public class MinionThrower : MonoBehaviour {
if (context.performed) { if (context.performed) {
isInThrowMode = true; isInThrowMode = true;
aimArrow.SetActive(true); aimArrow.SetActive(true);
} else if (context.canceled) { } else if (context.canceled && throwDirection.magnitude >= playerStats.MinJoystickValueForThrowing) {
PerformThrow(); PerformThrow();
isInThrowMode = false; isInThrowMode = false;
aimArrow.SetActive(false); aimArrow.SetActive(false);
@ -58,7 +60,10 @@ public class MinionThrower : MonoBehaviour {
if (!gameFlowManager.CanDoAction) if (!gameFlowManager.CanDoAction)
return; return;
throwDirection = context.ReadValue<Vector2>().normalized; throwDirection = context.ReadValue<Vector2>();
if (throwDirection.sqrMagnitude > 1f)
throwDirection.Normalize();
if (vampireEntity.playerMovement.facingRight) { if (vampireEntity.playerMovement.facingRight) {
aimArrow.transform.rotation = Quaternion.FromToRotation(Vector2.right, throwDirection); aimArrow.transform.rotation = Quaternion.FromToRotation(Vector2.right, throwDirection);
} else { } else {
@ -84,13 +89,16 @@ public class MinionThrower : MonoBehaviour {
var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, arena.minionParent) var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, arena.minionParent)
.GetComponent<Monster>(); .GetComponent<Monster>();
newMinion.arena = arena; newMinion.arena = arena;
newMinion.transform.position = transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f; if (throwDirection == Vector2.zero)
newMinion.direction = throwDirection; 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; newMinion.gameFlowManager = vampireEntity.gameFlowManager;
if (movement.GetSafeZoneIfImmobile() is { } safeZone) { if (movement.GetSafeZoneIfImmobile() is { } safeZone) {
newMinion.thrownFromSafeZone = true; newMinion.thrownFromSafeZone = true;
newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection); newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(normalizedDirection);
} }
} }

View File

@ -10,4 +10,7 @@ public class PlayerStats : ScriptableObject {
[field: SerializeField] [Min(0f)] [field: SerializeField] [Min(0f)]
public float bloodLossRate = 1f; public float bloodLossRate = 1f;
[field: SerializeField] [field: Range(0f, 1f)]
public float MinJoystickValueForThrowing { get; private set; } = .4f;
} }