Pages: 1
Author Topic: Get collision side?  (26,879 Views)
Offline (Unknown gender) cheeseboy

Administrator
Joined: Mar 2011
Posts: 105
View profile
Posted on: October 10, 2013, 05:25:41 AM
I want to get the side of a square another object collides with.

Heres what I've tried:

solution 1:
int hdis = (other.x - x);
int vdis = (other.y - y);
if (abs(hdis) < abs(vdis))
{
   if (hdis > 0)
room_caption="right";
    else
      room_caption="left";
}
else
{
    if (vdis > 0)
       room_caption="bottom";
    else
      room_caption="top";
}


solution 2:

int dir = (point_direction(x,y+sprite_get_width(mask_index)/2,other.x,other.y) / 90);


both are horribly inaccurate. Any way to do this better?
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: October 11, 2013, 12:42:15 PM
How exactly are they inaccurate? The first one is as easy as it gets and for a non-rotated right angle rectangle it should work just fine. For collision you of course must know trough which side it went. So you should take into account your previous positions as well.
Pages: 1