Player Animations

This commit is contained in:
Walter
2026-02-01 15:34:36 -06:00
parent 7362c7f57e
commit 1a498ce99d
8 changed files with 94 additions and 36 deletions
@@ -0,0 +1,10 @@
using UnityEngine;
public class PlayerAnimationController : MonoBehaviour
{
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fdb391b004c27a64da8f6922aab5512e
+34 -2
View File
@@ -20,6 +20,7 @@ public class PlayerPlatformerController : MonoBehaviour
private PlayerStressController playerStressController;
private PlayerPickupController playerPickupController;
private Animator animator;
private Rigidbody2D body;
private BoxCollider2D bodyCollider;
@@ -39,6 +40,7 @@ public class PlayerPlatformerController : MonoBehaviour
bodyCollider = GetComponent<BoxCollider2D>();
playerStressController = GetComponent<PlayerStressController>();
playerPickupController = GetComponent<PlayerPickupController>();
animator = GetComponent<Animator>();
}
private void OnEnable()
@@ -98,6 +100,11 @@ public class PlayerPlatformerController : MonoBehaviour
private void FixedUpdate()
{
if(IsGrounded())
{
animator.SetBool("isJumping", false);
}
if (healAction == null) return;
currentHealCoolDown++;
@@ -117,19 +124,25 @@ public class PlayerPlatformerController : MonoBehaviour
if (healAction.IsPressed())
{
if(playerPickupController.heldObject != null)
animator.SetBool("isBreathing", true);
if (playerPickupController.heldObject != null)
{
playerPickupController.DropObject(false);
}
if (canHeal)
{
playerStressController.ReduceStress(1f);
playerStressController.ReduceStress(3f);
canHeal = false;
}
return;
}
else
{
animator.SetBool("isBreathing", false);
}
var input = moveAction.ReadValue<Vector2>();
if (Mathf.Abs(input.x) > 0.01f)
@@ -139,6 +152,23 @@ public class PlayerPlatformerController : MonoBehaviour
var velocity = body.linearVelocity;
velocity.x = input.x * moveSpeed;
body.linearVelocity = velocity;
if(velocity.x != 0)
{
animator.SetBool("isRunning", true);
if (velocity.x > 0 && IsGrounded())
{
transform.localScale = new Vector3(.25f, .25f, .25f);
}
else
{
transform.localScale = new Vector3(-.25f, .25f, .25f);
}
}
else
{
animator.SetBool("isRunning", false);
}
}
private void OnJumpPerformed(InputAction.CallbackContext context)
@@ -154,6 +184,8 @@ public class PlayerPlatformerController : MonoBehaviour
velocity.y = 0f;
body.linearVelocity = velocity;
body.AddForce(Vector2.up * jumpImpulse, ForceMode2D.Impulse);
animator.SetBool("isJumping", true);
}
private bool ShouldFilterDevices()
+5 -1
View File
@@ -7,7 +7,8 @@ using UnityEngine;
public class PlayerStressController : MonoBehaviour
{
public PlayerPickupController pickupController;
private Animator animator;
[Header("Stress Settings")]
public float currentStress = 0f;
public float maxStress = 100f;
@@ -25,6 +26,7 @@ public class PlayerStressController : MonoBehaviour
void Start()
{
animator = GetComponent<Animator>();
// Start the repeating loop
StartCoroutine(StressCheckLoop());
}
@@ -76,6 +78,8 @@ public class PlayerStressController : MonoBehaviour
{
isPanicking = true;
animator.SetBool("isCollapsed", true);
Debug.Log("Player is freaking out man!");
// Add effects like screen shake or slowing down the player here
OnPlayerPanic?.Invoke(); // Trigger the panic event