Page 1 of 1

Collision/fixtures with irregular bodies?

Posted: Sat Jun 25, 2016 11:04 pm
by Zidbot2000
I am familiar with how to collide with regular shapes (like rectangles) but what if I have an object hidden behind an image like this: https://raw.githubusercontent.com/Jello ... eplat1.png
How do I create an object w/ a fixture for that so my other object (representing a player) can collide with it?

I don't think this needs a particular .love, but I'll attach one anyway (BEWARE: Spaghetti code).
In the .love, I made the drawing of the platform image a comment so there's just a circle at the moment.

Also, ignore the fact that the ball is falling and the rectangle is stationary, in this game the platform is supposed to move while the player does her animations in the center and the stage moves around her. This is so the player is always in the center. There is probably a much easier way to do this, but I've already committed to this bad idea. Regardless, this is a thread about the body.


tl;dr irregular bodies for colliding with?

Re: Collision/fixtures with irregular bodies?

Posted: Sun Jun 26, 2016 4:44 am
by ivan
love.physics or Box2D works with:
-convex polygons up to 8 vertices
-edges
-circles
So you have to use these shape types to represent whatever you need.

Also, if you're doing this by hand, it's probably better to start in reverse -
you create a map of polygons that actually works and is playable in Box2D,
then you slap an image on top that approximately fits your map.

Re: Collision/fixtures with irregular bodies?

Posted: Sun Jun 26, 2016 8:31 pm
by Zidbot2000
ivan wrote:love.physics or Box2D works with:
-convex polygons up to 8 vertices
-edges
-circles
So you have to use these shape types to represent whatever you need.

Also, if you're doing this by hand, it's probably better to start in reverse -
you create a map of polygons that actually works and is playable in Box2D,
then you slap an image on top that approximately fits your map.
Alright, sounds like a good idea! Thanks for the tip.