# How do I check for collision from the top part of a box?

Get help using Construct 2

### » Mon Nov 24, 2014 3:26 pm

Hey all

I've got 2 square sprites, and I want to perform something only when they hit from the top, meaning collision from the right side of a sprite will not perform the code.

Any idea on how to check it?

Thanks
B
18
S
7
G
1
Posts: 161
Reputation: 1,941

### » Mon Nov 24, 2014 3:41 pm

Hi @trueicecold Could you break the sprite into two parts, one (at the top) for detecting the collision and the other (at the bottom, but visually a continuation of the top) which just tags along for the ride?

Alternatively you could try some math on collision event regarding the position of both objects.
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

### » Mon Nov 24, 2014 3:46 pm

see 2 possible solutions:

1.- Use an invisible sprite "dummy", place it just on the top, and check for collisions.

2.- Compare positions of objects in the moment of the hit: If "Y" is lower, the object is higher and comes from above.

(lol, just the same as @hundredfold, seems we were writing at the same time...)
Last edited by clockworkmonster on Mon Nov 24, 2014 6:11 pm, edited 1 time in total.
B
12
S
2
Posts: 70
Reputation: 1,074

### » Mon Nov 24, 2014 4:52 pm

I have something similar in my game, a crate is broken if Player is on top.

Try this:
Square 1 --> On Collision w/ Square 2: Square 1--> (Add what you need here)
(Add Condition) Square 1--> (Compare Y) Y < Square 1.Y
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

### » Mon Nov 24, 2014 5:04 pm

lol @clockworkmonster - great minds think alike
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

### » Tue Nov 25, 2014 12:34 pm

Great stuff, thanks all!
B
18
S
7
G
1
Posts: 161
Reputation: 1,941