https://gyazo.com/4715b11e322ff556113efcba3899bba6 Справа находится боксерский коллайдер, отлично работающий при столкновении с игроком. Слева находится коллайдер карты тайлов, где игрок врезается в стену, пока я не позволю go клавиши со стрелкой.
Вот сценарий движения:
public float movementSpeed = 10f;
private float jumpThreshold = 0.01f;
public float jumpHeight = 5f;
private Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
Debug.Log(Physics2D.gravity.y);
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetButton("Jump"))
{
if (rb.velocity.y > -jumpThreshold && rb.velocity.y < jumpThreshold)
{
rb.AddForce(Vector3.up * jumpHeight, ForceMode2D.Impulse);
}
}
rb.AddForce(new Vector3(0f, -jumpHeight, 0f));
transform.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f) * movementSpeed * Time.deltaTime;
}