我的地砖和玩家移动 Unity 2D 有问题

Problem with my ground tiles and player movement Unity 2D

我的玩家在地砖上的移动有问题。这是我第一次试用 Unity 2D。我正在尝试构建一个简单的 2D plattformer.Suddenly 水平地面垂直并开始滚动 [

我认为问题出在 Tilemap Collider 2D 上,但我不太确定。以下是我目前用于玩家移动的脚本:

public class playerMovement2D:MonoBehaviour {

protected Rigidbody2D body;
protected Vector2 velocity;

public float jumpVelocity = 20.0f;

float horizontal;
float vertical;
bool isGrounded = false;
public Transform isGroundedChecker;
public float checkGroundRadius;
public LayerMask groundLayer;
public float runSpeed = 10.0f;
public float fallMultiplier = 2.5f;
public float lowJumpMultiplier = 2f;



// Start is called before the first frame update
void Start()
{
    body = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    Move();
    Jump();
    BetterJump();
    CheckIfGrounded();
   
}

private void Move()
{
    horizontal = Input.GetAxisRaw("Horizontal");
    float moveBy = horizontal * runSpeed;
    body.velocity = new Vector2(moveBy, body.velocity.y);

}

private void Jump()
{
    if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
    {
        body.velocity = new Vector2(jumpVelocity, body.velocity.x);
    }
}

void CheckIfGrounded()
{
    Collider2D collider = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
    if (collider != null)
    {
        isGrounded = true;
    }
    else
    {
        isGrounded = false;
    }
}

void BetterJump()
{
    if (body.velocity.y < 0)
    {
        body.velocity += Vector2.up * Physics2D.gravity * (fallMultiplier - 1) * Time.deltaTime;
    }
    else if (body.velocity.y > 0 && !Input.GetKey(KeyCode.Space))
    {
        body.velocity += Vector2.up * Physics2D.gravity * (lowJumpMultiplier - 1) * Time.deltaTime;
    }
}

}

您是否冻结了 Rigidbody 2D 组件中的旋转?它在限制条件下列出。