игрок проходит сквозь стены

сделал код передвижения для игры по типу subway surf, но игрок проходит сквозь препятствия, как можно исправить это?

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    public Rigidbody rb;

    public float runSpeed = 500f;
    public float strafeSpeed = 500f;
    public float JumpForce = 15f;
    protected bool strafeLeft = false;
    protected bool strafeRight = false;
    protected bool doJump = false;


    void Update()
    {
        if(Input.GetKey("a"))
        {
            strafeLeft = true;
        } else
        {
            strafeLeft = false;
        }

        if(Input.GetKey("d"))
        {
            strafeRight = true;
        } else
        {
            strafeRight = false;
        }
    }
    void FixedUpdate()
    {
        rb.MovePosition(transform.position + Vector3.forward * runSpeed * Time.deltaTime);
        if(strafeLeft)
        {
            rb.AddForce(-strafeSpeed * Time.deltaTime, 0,0, ForceMode.VelocityChange);
        }
        if (strafeRight)
        {
            rb.AddForce(strafeSpeed * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }
        if(doJump)
        {
            rb.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);

            doJump = false;
        }
    }
}

Ответы (0 шт):