Overlapping physics objects driving me mad :)

Hello all,

I’m having an issue with overlapping physics objects.

In the following video, you can see that when I create regular shaped physics objects close each other, their positions adjust to leave room to one another.


This works great until I have an elongated physics object. Then, creating an object close to the elongated one result in a crazy overlapping.

Here’s a little screen capture of the messy situation: https://dl.dropboxusercontent.com/u/73950/IMG_1747.jpg

I need to avoid that. I was thinking of testing for overlap (with body.testOverlap( otherBody )) every time I create a new object and force-change the y coordinate of one object so it moves higher up and the two objects are separated. But wouldn’t this end up taking al lot of resources? Also, it would most certainly screw with the goal of the game, which is to balance structures out.

Any idea on where this “bug” could come from, and how I could deal with it?


@Rodolphe Isn’t the object of your game to drop the shapes onto the pile and not create them in the pile. If you drop them, you won’t have the problem.

indeed, but -strategically- some shapes are best placed between others, already existing, objects. in order to consolidate the structure. I really need to keep this feature…

That makes sense. What if you only allow the long object to be dropped.

The same problem occurs when the long object already exists and another object is created right besides.

OK. Let me try some things and see what I come up with.

Thanks! :slight_smile:

maybe you could do this: start with a small object then make it grow bigger (replace it with a slightly bigger one) until you get the right shape? then maybe the room needed will be generated in the process, pushing other objects, and you get what you want.

hmmm, that’s a lead! thanks!

One problem with that is if the (long) object goes between two objects. Instead of landing on them, it’s will push them apart as it grows to it original size.

Yes indeed… I’m starting to think that testing for overlap every time I create a new object and, if True, force-changing the y coordinate of one object so it moves up or do, is the most sensible solution. hmm :frowning:

@Rodolphe I created a test with a pile of objects. When I create a long, skinny objects randomly in the pile, it pushes everything out of its way. As I continue to create the skinny object in the pile, everything gets pushed to the side or pushed up. I have no overlapping objects.

Thanks for the test @dave1707!

I noticed it mainly happens with an object I create like this (the one on the picture and video). Could I be doing this wrong?

local r1 = 920.0*math.random(98,102)/100.0
local e = 2520.0*math.random(98,102)/100.0
local a = math.random(0.0,math.pi*100.0)/100

points = {

I don’t know why, but I feel the problem might actually be related to these tripod shapes, and not the long blocks…

@Rodolphe I haven’t tried to use that code to create an object yet, but if the points aren’t in a clockwise or counter clockwise order, then they won’t create the object you think they will. I’ll use the code above and see the order of the points. That probably is the problem because no matter how many objects I created in my test, I didn’t have any overlaps.

@Rodolphe The points you create with the code above are created in a counter clockwise order. I took your code and created objects with them. I created a pile of 40 of them and then started to create them within the pile. Depending on where the objects were, they DID overlap and they wouldn’t seperate. It appears that objects created with more than 4 point ( ? ) can overlap and they get stuck trying to seperate.

@dave1707, could you try setting the objects as bullets in your test? A Google search I did turned that up as a potential fix.

Thanks @dave1707, this is useful! do all the other objects of your test have 3 points?

I’ll try to set them as bullets too, and see what happens, thanks @Jakattak. What’s the downside of this by the way?

@Rodolphe In my original test, all the objects had 4 points. I’ll try setting bullets in the second test and see what happens. It won’t be for awhile because I have to go somewhere first.

I just tried bullet, actually, and it doesn’t solve my problem… I also tried physics.iterations(100,100) (instead of the default 10,8), but it still happens.

Oops, I forgot to set physics.continuous to True before using bullet. when I set bullet to only tripods shapes, it seems to behave better (the shapes still overlap, but are pushed away from each other a bit faster than before). I’m testing further…

By the way, could the concave shape of the tripods be the reason for this mess?