【发布时间】:2021-06-16 21:26:15
【问题描述】:
我正在制作 PacMan 类型的游戏,只是为了好玩,但我遇到了问题。我已经创建了一个角色并使用 tilemaps 制作了一张地图。我将 tilemap collider 2d 添加到 tilemap 和 box collider 2d 以及用于角色的刚体(运动学)。这是我的移动代码:
public class PlayerController : MonoBehaviour
{
[SerializeField]
private float _speed = 3.0f;
private Vector2 _direction = Vector2.zero;
private void Start()
{
}
private void Update()
{
Move();
CheckInput();
}
private void CheckInput()
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
_direction = Vector2.left;
} else if (Input.GetKeyDown(KeyCode.RightArrow))
{
_direction = Vector2.right;
} else if (Input.GetKeyDown(KeyCode.UpArrow))
{
_direction = Vector2.up;
} else if (Input.GetKeyDown(KeyCode.DownArrow))
{
_direction = Vector2.down;
}
}
private void Move()
{
transform.localPosition += (Vector3)(_direction * _speed) * Time.deltaTime;
}
}
我已更改“联系人配对模式”,但它不起作用。这是我的问题的照片: collision problem
【问题讨论】: