# Testing edge collisions?

Get help using Construct 2

### » Sun Jan 11, 2015 5:40 pm

How would one go about detecting which side an object collided on? e.g..

+Bullet collides with wall on the RIGHT
-Do this

+Bullet collides with wall on the BOTTOM
-Do that

'Overlapping at offset' doesn't cut it because it's the same type of collision..just at an offset.

All I can think of is using detector objects but...ew. Any other ideas?
B
251
S
32
G
13
Posts: 1,794
Reputation: 19,193

### » Sun Jan 11, 2015 5:46 pm

Do a rough position comparison, like if X is within object size and y is below center it's probably a bottom hit, if y is within object size and X is outside it's probably a side hit?
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

### » Sun Jan 11, 2015 8:13 pm

That'd work for objects but not walls/tilemaps :T
B
251
S
32
G
13
Posts: 1,794
Reputation: 19,193

### » Sun Jan 11, 2015 8:53 pm

Hmm, if you have some kinda index of the tilemap you could calculate those coordinates, probably.
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

### » Sun Jan 11, 2015 10:18 pm

I would try using the "Is overlapping at offset" condition by checking if overlaps the wall when the it is displaced to the left/right of its current position. I imagine that this might not give perfect results if your bullets are very fast, but if the check is triggered by a collision trigger then I think it should work - you might just have to play around with how far left/right you have to check, or you could check in increments by increasing the displacement if the first check renders a no-overlap on both sides.
Learning Unity, but C2 still rocks.
B
78
S
20
G
92
Posts: 2,407
Reputation: 55,901

### » Fri Jan 16, 2015 6:29 pm

@Tokinsom it seems like I've had some good results with offset collision and have been able to create some more complex behaviors... but I've also run into some limitations. maybe I'm not understanding what you're trying to accomplish though - what do you want to happen when the bullet collides with the wall on the right?
B
85
S
24
G
10
Posts: 399
Reputation: 10,581

### » Fri Jan 16, 2015 6:31 pm

I guess there's always bounding boxes too (bbox right) - you'd probably have to do for each instance, and then check for the X of an object is within (distance) X pixels of a wall... but I'm not sure if that would work with a tilemap, since it's one large object itself.
B
85
S
24
G
10
Posts: 399
Reputation: 10,581

### » Fri Jan 16, 2015 11:28 pm

Overlapping at offset works to an extent, but is not perfect. For example, if a bullet is moving at ~60 degrees and hits a wall at the right it could return both a right-side and bottom-side collision. Sames goes for corners.

I guess I'll just settle with detector objects positioned to bullets based on size, and put them in a container. Not the most elegant solution but it should do the trick.
B
251
S
32
G
13
Posts: 1,794
Reputation: 19,193

### » Sat Jan 17, 2015 1:52 am

Here's how I would do it using just offset collision detection. I could probably tidy this example up a bit but I'm sure you'll get the idea - hope it helps!
You do not have the required permissions to view the files attached to this post.
Learning Unity, but C2 still rocks.
B
78
S
20
G
92
Posts: 2,407
Reputation: 55,901

### Who is online

Users browsing this forum: No registered users and 27 guests