Collision/fixtures with irregular bodies?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Zidbot2000
Prole
Posts: 3
Joined: Sat Jun 25, 2016 10:54 pm

Collision/fixtures with irregular bodies?

Post 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?
Attachments
BleedAgain.love
(2.04 MiB) Downloaded 121 times
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collision/fixtures with irregular bodies?

Post 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.
Zidbot2000
Prole
Posts: 3
Joined: Sat Jun 25, 2016 10:54 pm

Re: Collision/fixtures with irregular bodies?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 222 guests