2D Tilemap-Navigation by click to move

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Arkin45

Hi,
so I tried to make this work, but so far I didn’t quite get there. (Also I’m pretty new to programming)
What I wanted to achieve is, that when I click at a point on my screen my character will move there, without moving through or into the walls.
I have a navigation2D node with a tilemap as a child. The walls have Collision that i added with the tile editor, and the floor has navigation.
So with get_simple_path I wanted to make my kinematicbody2D character move. I found a script online that would do that, but I figured out that that script just changes the position of the character, so it can’t collide with the walls, so when I click into a wall the sprite (and collisionshape) of the character will overlap with the walls.
(this is how my navigation was made: https://www.youtube.com/watch?v=0fPOt0Jw52s)

  • It would be possible that I create an extra tilemap for the nav2D node that takes the size of the sprite into account so it wouldn’t overlap with the walls, but that would mean, if I create bigger or smaller mobs they would need there own navmesh again. (but still I’m not sure if changing the position is the best solution)
  • Or I could make the character move by physics? so it collides with the wall when it gets to close. But then I wouldn’t know how to let it still get to it’s target.

So I hope I could get my problem across. If somebody can point me in the right direction or has some code or anything really to help me out, I’d be really thankful :smiley: