1
votes

I am working on a 2D game with a Grid with 2 tilemaps in it. The walkable tilemap and the obstacles tilemap. I gave the obstacle tilemap the tilemapcollider2d. I want my player to have a kinematic rigidbody so physics won't do weird things after colliding with the obstacle tiles.

The thing is, the player only collides with the obstacle tiles if it has a dynamic rigidbody. How can I make the player collide with the obstacle tiles, while having a kinematic rigidbody?

I also tried adding a rigidbody2d to the obstacles tilemap but this doesn't have any effect. Unless it's set to dynamic, then all the obstacle tiles start falling down but do collide with the player for a moment before the player clips through it.

This the code for the movement of my player (body = the RigidBody2D of the player):

void Update()
{
    // Gives a value between -1 and 1
    horizontal = Input.GetAxisRaw("Horizontal"); // -1 is left
    vertical = Input.GetAxisRaw("Vertical"); // -1 is down
}

void FixedUpdate()
{
    if (horizontal != 0 && vertical != 0) // Check for diagonal movement
    {
        // limit movement speed diagonally, so you move at 70% speed
        horizontal *= moveLimiter;
        vertical *= moveLimiter;
    }

    body.velocity = new Vector2(horizontal * Speed, vertical * Speed);
}

Thanks in advance!

1
Anyone? Still haven't solved it :(Ricardo Frederiks
Still having this issue. How can I make a kinematic rigidbody collide with a tilemap collider?Ricardo Frederiks

1 Answers

-1
votes

I guess you just want the player to stop when he hits the obstacle tile-map

Solution : Add box Collider 2D for both player and the obstacle tile-map

If you want to detect collision try using trigger