Fixed throwing minions without direction
This commit is contained in:
parent
5545e42e5a
commit
5440c56426
@ -69,6 +69,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 3d475633c5bc498fac5a9e5ead64da55, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
arena: {fileID: 0}
|
||||
gameFlowManager: {fileID: 0}
|
||||
<Health>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}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<Vector2>().normalized;
|
||||
throwDirection = context.ReadValue<Vector2>();
|
||||
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<Monster>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user