2025-01-10 16:14:33 -05:00
|
|
|
using System.Collections;
|
2025-01-17 20:11:04 -05:00
|
|
|
using TMPro;
|
2025-03-08 13:33:19 -05:00
|
|
|
using Unity.IO.LowLevel.Unsafe;
|
2025-04-17 18:32:27 -04:00
|
|
|
using UnityEngine;
|
|
|
|
|
using Game;
|
|
|
|
|
using Music;
|
|
|
|
|
using Player;
|
2025-01-10 16:14:33 -05:00
|
|
|
using UnityEngine.InputSystem;
|
2025-04-16 19:57:54 -04:00
|
|
|
namespace Player
|
|
|
|
|
{
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
|
[RequireComponent(typeof(BoxCollider2D))]
|
|
|
|
|
[RequireComponent(typeof(PlayerInput))]
|
|
|
|
|
[RequireComponent(typeof(AnimationPlayer))]
|
|
|
|
|
[RequireComponent(typeof(Punch))]
|
|
|
|
|
public class PlayerMovement : MonoBehaviour
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-03-07 10:46:30 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Layers considered as ground for the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Header("Ground Layers")]
|
|
|
|
|
public LayerMask ground;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the player's UI text displaying player index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextMeshProUGUI playerText;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base walk speed of the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Header("Movement")]
|
|
|
|
|
public float walkSpeed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Multiplier applied to walk speed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float walkSpeedFactor = 1f;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maximum allowed horizontal speed for the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float maxSpeed = 5f;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runtime override for the maximum speed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float maxSpeedOverride;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Multiplier for slowing down the player when exceeding max speed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float slowdownMultiplier = 10f;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Current value of the horizontal movement axis.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float virtualAxisX;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Current value of the jump button (pressed or not).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float virtualButtonJump;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Value of the jump button in the previous frame.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float virtualButtonJumpLastFrame;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Multiplier applied when turning around to adjust speed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float turnaroundMultiplier = 2;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Smoothing factor for walking movement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float walkSmooth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Time in seconds to reach full speed from rest.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float secondsToFullSpeed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Force applied when jumping.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float jumpSpeed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Time window after leaving ground where jump is still allowed (coyote time).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float coyoteTime;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Time window after pressing jump where jump is still buffered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float jumpLenience;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Minimum time before the player can be declared as not jumping.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float timeUnableToBeDeclaredNotJumping = 0.1f;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Distance to check below the player for ground detection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float groundCheckDistance;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the Rigidbody2D component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Rigidbody2D body;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the BoxCollider2D component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private BoxCollider2D collide;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the PlayerInput component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private PlayerInput input;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the AnimationPlayer component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AnimationPlayer animationPlayer;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the Punch component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Punch punch;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference to the Damageable component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Damageable damageable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the jump input is still valid for buffered jumps.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool jumpInputStillValid = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the player can be declared as not jumping.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool canBeDeclaredNotJumping = true;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if jump physics should be applied this frame.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool jumpPhysics;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the player is currently jumping.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool jumping;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The last time the jump button was pressed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private float lastTimeJumpPressed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The last time the player was on the ground.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private float lastTimeOnGround;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's position in the previous frame.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Vector3 positionLastFrame;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes player components and sets up initial values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
maxSpeedOverride = maxSpeed;
|
|
|
|
|
GetComponent<RespawnOnTriggerEnter>().spawnPoint = transform.position;
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
body = GetComponent<Rigidbody2D>();
|
|
|
|
|
collide = GetComponent<BoxCollider2D>();
|
|
|
|
|
input = GetComponent<PlayerInput>();
|
|
|
|
|
animationPlayer = GetComponent<AnimationPlayer>();
|
|
|
|
|
punch = GetComponent<Punch>();
|
|
|
|
|
damageable = GetComponent<Damageable>();
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
playerText.text = input.playerIndex.ToString();
|
|
|
|
|
}
|
2025-01-15 16:55:07 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles per-frame updates for player movement and jump input.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Update()
|
2025-01-15 16:55:07 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (GameManager.Instance != null && GameManager.Instance.gameOver) maxSpeed = 1f;
|
|
|
|
|
UpdateVirtualAxis();
|
|
|
|
|
if (damageable.dying) return;
|
|
|
|
|
Jump();
|
2025-01-15 16:55:07 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles physics-based updates for jumping and horizontal movement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void FixedUpdate()
|
2025-04-16 19:20:36 -04:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
JumpPhysics();
|
|
|
|
|
HorizontalMovement();
|
|
|
|
|
Land();
|
2025-04-16 19:20:36 -04:00
|
|
|
}
|
2025-04-17 18:32:27 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles late frame updates, such as animation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void LateUpdate()
|
2025-04-16 19:20:36 -04:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
Animate();
|
2025-04-16 19:20:36 -04:00
|
|
|
}
|
2025-01-15 16:55:07 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the player's animation state based on movement and grounded status.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Animate()
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (!IsPhysicallyGrounded())
|
|
|
|
|
animationPlayer.SetState(AnimationPlayer.AnimationState.Jump);
|
|
|
|
|
else
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (Mathf.Abs(virtualAxisX) >= 0.05f)
|
|
|
|
|
animationPlayer.SetState(GameManager.Instance.gameOver ? AnimationPlayer.AnimationState.Walk : AnimationPlayer.AnimationState.Run);
|
|
|
|
|
else
|
|
|
|
|
animationPlayer.SetState(AnimationPlayer.AnimationState.Idle);
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (true)
|
|
|
|
|
{
|
|
|
|
|
if (virtualAxisX < -0.01f)
|
|
|
|
|
animationPlayer.backwards = true;
|
|
|
|
|
else if (virtualAxisX > 0.01f)
|
|
|
|
|
animationPlayer.backwards = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (body.linearVelocityX < -0.1f)
|
|
|
|
|
animationPlayer.backwards = true;
|
|
|
|
|
else if (body.linearVelocityX > 0.1f)
|
|
|
|
|
animationPlayer.backwards = false;
|
|
|
|
|
}
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles logic for landing and stopping the jump state when grounded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Land()
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (body.linearVelocity.y >= 0f) return;
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (IsPhysicallyGrounded())
|
2025-02-08 18:54:21 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (canBeDeclaredNotJumping)
|
2025-02-09 17:18:51 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
jumping = false;
|
2025-02-09 17:18:51 -05:00
|
|
|
}
|
2025-02-08 18:54:21 -05:00
|
|
|
}
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles jump input and determines if a jump should be triggered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Jump()
|
2025-02-08 18:54:21 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (virtualButtonJumpLastFrame == 1f)
|
|
|
|
|
{
|
|
|
|
|
jumpInputStillValid = true;
|
|
|
|
|
lastTimeJumpPressed = Time.time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isBasicallyGrounded = IsBasicallyGrounded();
|
|
|
|
|
if ((virtualButtonJumpLastFrame == 1f && isBasicallyGrounded && jumping == false)
|
|
|
|
|
|| (jumpInputStillValid && Time.time - lastTimeJumpPressed <= jumpLenience && IsPhysicallyGrounded()))
|
|
|
|
|
{
|
|
|
|
|
AudioManager.Instance.PlaySound("Jump");
|
|
|
|
|
jumpPhysics = true;
|
|
|
|
|
jumping = true;
|
|
|
|
|
jumpInputStillValid = false;
|
|
|
|
|
StartCoroutine(NotJumpingDelay());
|
|
|
|
|
}
|
2025-02-08 18:54:21 -05:00
|
|
|
}
|
2025-01-13 15:58:50 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Applies jump physics and forces to the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void JumpPhysics()
|
2025-01-13 15:58:50 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
if (jumpPhysics)
|
|
|
|
|
{
|
|
|
|
|
if (!GetComponent<Block>().blocking)
|
|
|
|
|
{
|
|
|
|
|
if (body.linearVelocity.y < 0 || !IsPhysicallyGrounded()) body.linearVelocity = new Vector2(body.linearVelocity.x, 0);
|
|
|
|
|
body.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
|
|
|
|
|
if (Mathf.Abs(body.linearVelocityX) > maxSpeed)
|
|
|
|
|
{
|
|
|
|
|
body.linearVelocity = new Vector2(Mathf.Sign(body.linearVelocityX) * maxSpeed, body.linearVelocity.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
jumpPhysics = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IsPhysicallyGrounded() && !(virtualButtonJump == 1f))
|
|
|
|
|
body.AddForce(Vector2.down * jumpSpeed);
|
2025-01-13 15:58:50 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Coroutine that delays the ability to declare the player as not jumping.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerator NotJumpingDelay()
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
canBeDeclaredNotJumping = false;
|
|
|
|
|
yield return new WaitUntil(() => !IsBasicallyGrounded());
|
|
|
|
|
canBeDeclaredNotJumping = true;
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles horizontal movement, including acceleration, deceleration, and blocking.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void HorizontalMovement()
|
2025-02-09 17:18:51 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
float temporaryMax = IsPhysicallyGrounded() ? maxSpeedOverride : Mathf.Infinity;
|
|
|
|
|
float temporarySlowdown = IsPhysicallyGrounded() ? slowdownMultiplier : 1;
|
2025-02-09 17:18:51 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (!GetComponent<Block>().blocking && (Mathf.Abs(body.linearVelocityX) <= maxSpeed || Mathf.Sign(body.linearVelocityX) != Mathf.Sign(virtualAxisX)))
|
|
|
|
|
{
|
|
|
|
|
body.AddForce(new Vector2(virtualAxisX * walkSpeed * walkSpeedFactor, 0), ForceMode2D.Force);
|
|
|
|
|
}
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (Mathf.Abs(body.linearVelocityX) >= temporaryMax)
|
|
|
|
|
{
|
|
|
|
|
body.AddForce(new Vector2(-Mathf.Sign(body.linearVelocityX) * (Mathf.Abs(body.linearVelocityX) - temporaryMax) * temporarySlowdown, 0));
|
|
|
|
|
}
|
2025-01-13 15:58:50 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (transform.position == positionLastFrame && (input.actions.FindAction("Move").ReadValue<Vector2>().x == 0))
|
|
|
|
|
{
|
|
|
|
|
virtualAxisX = 0;
|
|
|
|
|
}
|
2025-01-14 11:40:09 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (GetComponent<Block>().blocking)
|
|
|
|
|
{
|
|
|
|
|
body.AddForce(new Vector2(-body.linearVelocityX * 0.8f, 0), ForceMode2D.Force);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
positionLastFrame = transform.position;
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the virtual axis and button values from input actions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateVirtualAxis()
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
virtualButtonJump = input.actions.FindAction("Action").ReadValue<float>();
|
|
|
|
|
virtualButtonJumpLastFrame = input.actions.FindAction("Action").WasPressedThisFrame() ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
virtualAxisX = input.actions.FindAction("Move").ReadValue<Vector2>().x;
|
|
|
|
|
return;
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the player is considered grounded, including coyote time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if the player is basically grounded, otherwise false.</returns>
|
|
|
|
|
public bool IsBasicallyGrounded()
|
|
|
|
|
{
|
|
|
|
|
if (IsPhysicallyGrounded())
|
|
|
|
|
{
|
|
|
|
|
lastTimeOnGround = Time.time;
|
|
|
|
|
}
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
if (Time.time - lastTimeOnGround < coyoteTime)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the player is physically touching the ground using raycasts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if the player is physically grounded, otherwise false.</returns>
|
|
|
|
|
public bool IsPhysicallyGrounded()
|
2025-01-10 16:14:33 -05:00
|
|
|
{
|
2025-04-17 18:32:27 -04:00
|
|
|
RaycastHit2D leftCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, -1, -1), Vector2.down, groundCheckDistance, ground);
|
|
|
|
|
RaycastHit2D rightCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, 1, -1), Vector2.down, groundCheckDistance, ground);
|
|
|
|
|
RaycastHit2D midCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, 0, -1), Vector2.down, groundCheckDistance, ground);
|
|
|
|
|
|
|
|
|
|
if (leftCheck || rightCheck || midCheck)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2025-01-10 16:14:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a point on the BoxCollider2D based on horizontal and vertical multipliers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="boxCollider2D">The BoxCollider2D to use.</param>
|
|
|
|
|
/// <param name="horizontal">Horizontal offset (-1 for left, 1 for right, 0 for center).</param>
|
|
|
|
|
/// <param name="vertical">Vertical offset (-1 for bottom, 1 for top, 0 for center).</param>
|
|
|
|
|
/// <returns>The calculated point in world space.</returns>
|
|
|
|
|
public Vector2 GetPointInBoxCollider(BoxCollider2D boxCollider2D, float horizontal, float vertical)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2
|
|
|
|
|
(
|
|
|
|
|
boxCollider2D.bounds.center.x + (horizontal * boxCollider2D.bounds.extents.x),
|
|
|
|
|
boxCollider2D.bounds.center.y + (vertical * boxCollider2D.bounds.extents.y)
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-01-10 16:14:33 -05:00
|
|
|
|
2025-04-17 18:32:27 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Stops the player's velocity if grounded, removing inertia.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void StopVelocity()
|
|
|
|
|
{
|
|
|
|
|
if (IsPhysicallyGrounded()) body.linearVelocity = Vector2.zero;
|
|
|
|
|
}
|
2025-01-17 19:46:17 -05:00
|
|
|
|
|
|
|
|
}
|
2025-04-16 19:57:54 -04:00
|
|
|
}
|