Testing edge collisions?

0 favourites
  • 9 posts
From the Asset Store
On the Edge is a puzzle game where you have 40 levels to have fun with.
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

  • That'd work for objects but not walls/tilemaps :T

  • Hmm, if you have some kinda index of the tilemap you could calculate those coordinates, probably.

  • 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.

  • 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?

  • 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.

  • 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.

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)