Merge branch 'main' into trick-enhancements
This commit is contained in:
@@ -10,7 +10,7 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
[SerializeField] private string actionMapName = "Player";
|
||||
[SerializeField] private string moveActionName = "Move";
|
||||
[SerializeField] private string jumpActionName = "Jump";
|
||||
[SerializeField] private string healActionName = "Crouch";
|
||||
[SerializeField] private string healActionName = "Heal";
|
||||
[SerializeField] private string controlSchemeName = "";
|
||||
[SerializeField] private int gamepadIndex = -1;
|
||||
[SerializeField] private float moveSpeed = 6f;
|
||||
@@ -19,6 +19,8 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
[SerializeField] private float groundCheckDistance = 0.05f;
|
||||
|
||||
private PlayerStressController playerStressController;
|
||||
private PlayerPickupController playerPickupController;
|
||||
private Animator animator;
|
||||
|
||||
private Rigidbody2D body;
|
||||
private BoxCollider2D bodyCollider;
|
||||
@@ -28,12 +30,17 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
private InputAction healAction;
|
||||
public float LastMoveX { get; private set; }
|
||||
private bool deviceFilterEnabled;
|
||||
private int healCoolDownTicks = 15;
|
||||
private int currentHealCoolDown = 0;
|
||||
private bool canHeal = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
body = GetComponent<Rigidbody2D>();
|
||||
bodyCollider = GetComponent<BoxCollider2D>();
|
||||
playerStressController = GetComponent<PlayerStressController>();
|
||||
playerPickupController = GetComponent<PlayerPickupController>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -56,10 +63,12 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
var map = runtimeActions.FindActionMap(actionMapName, true);
|
||||
moveAction = map.FindAction(moveActionName, true);
|
||||
jumpAction = map.FindAction(jumpActionName, true);
|
||||
healAction = map.FindAction(healActionName, true);
|
||||
|
||||
moveAction.Enable();
|
||||
jumpAction.Enable();
|
||||
jumpAction.performed += OnJumpPerformed;
|
||||
healAction.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -75,6 +84,11 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
moveAction.Disable();
|
||||
}
|
||||
|
||||
if (healAction != null)
|
||||
{
|
||||
healAction.Disable();
|
||||
}
|
||||
|
||||
if (runtimeActions != null)
|
||||
{
|
||||
runtimeActions.Disable();
|
||||
@@ -86,6 +100,21 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(IsGrounded())
|
||||
{
|
||||
animator.SetBool("isJumping", false);
|
||||
}
|
||||
|
||||
if (healAction == null) return;
|
||||
|
||||
currentHealCoolDown++;
|
||||
|
||||
if (currentHealCoolDown >= healCoolDownTicks)
|
||||
{
|
||||
currentHealCoolDown = 0;
|
||||
canHeal = true;
|
||||
}
|
||||
|
||||
if (moveAction == null)
|
||||
{
|
||||
return;
|
||||
@@ -93,6 +122,28 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
|
||||
if (playerStressController.isPanicking) return;
|
||||
|
||||
if (healAction.IsPressed())
|
||||
{
|
||||
animator.SetBool("isBreathing", true);
|
||||
|
||||
if (playerPickupController.heldObject != null)
|
||||
{
|
||||
playerPickupController.DropObject(false);
|
||||
}
|
||||
|
||||
if (canHeal)
|
||||
{
|
||||
playerStressController.ReduceStress(3f);
|
||||
canHeal = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.SetBool("isBreathing", false);
|
||||
}
|
||||
|
||||
var input = moveAction.ReadValue<Vector2>();
|
||||
if (Mathf.Abs(input.x) > 0.01f)
|
||||
{
|
||||
@@ -101,11 +152,28 @@ 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)
|
||||
{
|
||||
if (playerStressController.isPanicking) return;
|
||||
if (playerStressController.isPanicking || healAction.IsPressed()) return;
|
||||
|
||||
if (!IsGrounded())
|
||||
{
|
||||
@@ -116,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()
|
||||
|
||||
Reference in New Issue
Block a user