Я сделал небольшую карту со стенами по краям и когда я прыгнул на стену и зажал кнопку движения в сторону стены на которую прыгнул то мой персонаж замер в воздухе. Когда я отжал кнопку движения он упал.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private GameObject Player;
[SerializeField] private Rigidbody2D PlayerRigidbody;
[SerializeField] private float PlayerSpeed;
[SerializeField] private float JumpForce;
[SerializeField] private float MaxPlayerSpeed;
[SerializeField] private bool RightFacing;
private bool OnGround;
private float PlayerHorizontalMove;
private void Start()
{
PlayerRigidbody = Player.GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
MovementLogic();
JumpLogic();
}
void Update()
{
PlayerHorizontalMove = Input.GetAxis("Horizontal") * PlayerSpeed;
if (PlayerRigidbody.velocity.magnitude >= MaxPlayerSpeed)
{
PlayerRigidbody.velocity = PlayerRigidbody.velocity.normalized * MaxPlayerSpeed;
}
}
private void MovementLogic()
{
PlayerRigidbody.velocity = new Vector2(PlayerHorizontalMove, PlayerRigidbody.velocity.y);
}
private void JumpLogic()
{
if (Input.GetAxis("Jump") != 0 && OnGround)
{
PlayerRigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
private void Flip()
{
RightFacing = !RightFacing;
}
private void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("CanJump"))
{
OnGround = true;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
OnGround = false;
}
}