Testing edge collisions?

Get help using Construct 2

Post » 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?
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » 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
6
Posts: 1,101
Reputation: 5,646

Post » Sun Jan 11, 2015 8:13 pm

That'd work for objects but not walls/tilemaps :T
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » 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
6
Posts: 1,101
Reputation: 5,646

Post » 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.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » 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
73
S
19
G
9
Posts: 376
Reputation: 9,231

Post » 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
73
S
19
G
9
Posts: 376
Reputation: 9,231

Post » 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.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » 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.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 31 guests