Pages: 1
  Print  
Author Topic: Get collision side?  (Read 981 times)
Offline (Male) cheeseboy
Posted on: October 10, 2013, 12:25:41 AM

Member
Location: The internet
Joined: Mar 2011
Posts: 106

View Profile
I want to get the side of a square another object collides with.

Heres what I've tried:

solution 1:
Code: [Select]
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:
Code: [Select]
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?
« Last Edit: October 10, 2013, 12:28:20 AM by cheeseboy » Logged
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: October 11, 2013, 07:42:15 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
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.
Logged
Pages: 1
  Print