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!