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.
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…
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.
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
@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.
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 = {
vec2(0,e*(math.random(90,100)/100)):rotate(2*math.pi/1.03):rotate(a),
vec2(0,e*(math.random(90,100)/100)):rotate(2*math.pi/.97):rotate(a),
vec2(0,r1*(math.random(95,105)/100)):rotate(2*math.pi/6):rotate(a),
vec2(0,e*(math.random(90,100)/100)):rotate(2*math.pi/3.27):rotate(a),
vec2(0,e*(math.random(90,100)/100)):rotate(2*math.pi/2.77):rotate(a),
vec2(0,r1*(math.random(95,105)/100)):rotate(math.pi):rotate(a),
vec2(0,e*(math.random(90,100)/100)):rotate(2*math.pi/1.56):rotate(a),
vec2(0,e*(math.random(90,100)/100)):rotate(2*math.pi/1.44):rotate(a),
vec2(0,r1*(math.random(95,105)/100)):rotate(2*math.pi/1.2):rotate(a)
}
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.
@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?