2D top view collisions (SOLVED)

Hi !

Have you any idea about how can I get the position of a wall colliding with my player? I struggle with that for hours now because collisions are tricky (like in every game engine).
:warning: It’s a top view 2D game (like old Dragon Quest) so I use no gravity, I tried to use the platform tutorial but I can’t just copy past it because it is made for a game with gravity :confused:
My world is a tilemap so I can’t use the “message.other_position”.

All I need is being able to tell :

  • do the object collides with a wall on north (positive Y)?
  • do the object collides with a wall on east (negative X)?
  • do the object collides with a wall on west (positive X)?
  • do the object collides with a wall on south (negative Y)?

I tried using contact normals but it has like 10% chances of randomly returning a wrong direction, it makes my player entering the walls or getting stuck, I also tried using contact point position but it is always located to a corner of the hitbox so it’s impossible to tell if the player is colliding with only (for example) a wall on the north or a wall on the west or both…

Ray casts is a solution to your problem. Do collision separation using contact_point_response messages and then also cast rays to detect direction of walls. Remember that ray casts are asynchronous, but in your case it should hardly matter.

2 Likes

Works like a charm !
I thought ray cast was a heavy method in terms of process and code seize but in fact it’s soft and easy !
Thank you for quick answer !

1 Like