# 2D top view collisions (SOLVED)

**URL:** <https://forum.defold.com/t/2d-top-view-collisions-solved/19179>\
**Category:** Questions\
**Created:** [April 21, 2018, 10:36am UTC](https://forum.defold.com/t/2d-top-view-collisions-solved/19179 "2018-04-21T10:36:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maelig.moreau](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/maelig.moreau/32/6991_2.png) [@maelig.moreau](https://forum.defold.com/u/maelig.moreau)\
**Post date:** [April 21, 2018, 10:36am UTC](https://forum.defold.com/t/2d-top-view-collisions-solved/19179/1 "2018-04-21T10:36:10Z")

</div>

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).  
⚠ 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 😕  
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…

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 21, 2018, 11:37am UTC](https://forum.defold.com/t/2d-top-view-collisions-solved/19179/2 "2018-04-21T11:37:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maelig.moreau](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/maelig.moreau/32/6991_2.png) [@maelig.moreau](https://forum.defold.com/u/maelig.moreau)\
**Post date:** [April 21, 2018, 1:00pm UTC](https://forum.defold.com/t/2d-top-view-collisions-solved/19179/3 "2018-04-21T13:00:43Z")

</div>

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 !
