How do I determined the side of a collision ?

Get help using Construct 2

» Sun Feb 26, 2017 1:33 am

How can i get collision sides of an object -

e.g. top / bottom , left / right with a rectangle ?
B
9
S
3
G
4
Posts: 58
Reputation: 2,799

» Sun Feb 26, 2017 3:32 am

Pin additionable hitboxes like these which is quite reliable with simple objects or use formulas to calculate relative posotion of projectile right before collision.
colX = object.X - projectile.X
colY = object.Y - projectile.Y

If colX > 0 & colY < 0 & colX > colY then it was hit from left
If colX > 0 & colY < 0 & colX < colY then it got the bottom and etc.
B
8
S
1
G
2
Posts: 19
Reputation: 938

» Sun Feb 26, 2017 4:20 am

Wow, i hoped there would be a simpler solution -

the mathematical one is probably the better one in Terms of Memory usage -
but the worse one in Terms of brain capabilities

! colX > colY ! this third condition i was missing ;

thanks a lot for the detailed answer !
B
9
S
3
G
4
Posts: 58
Reputation: 2,799

» Sun Feb 26, 2017 4:30 am

angle(x0,y0,x1,y1) gives you the angle between two objects
That can be use to determine a side.
For example if the return was 0 degrees you would know it was on the right side.
B
173
S
50
G
195
Posts: 8,578
Reputation: 121,892