I'm making PacMan type game, just for fun and i have a problem. I've created a character and made a map with tilemaps. I added tilemap collider 2d to tilemap and box collider 2d and rigidbody(kinematic) for character. Here is my code for movement:
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;
}
}
I've changed the "Contact pairs mode" but it didn't work. Here is the photo of my problem: collision problem