Circle-Circle impulse resolution not working properly

Started by
23 comments, last by Dirk Gregorius 6 years, 9 months ago

I would try with zero penetration recovery and restitution first. Then add penetration recovery and finally restitution. 

Advertisement
Just now, Dirk Gregorius said:

I would try with zero penetration recovery and restitution first.

What does that mean?

That means, I would first not worry about penetration recovery and don't support restitution. In particular getting penetration recovery and restitution work correct together can be tricky.

3 minutes ago, Dirk Gregorius said:

That means, I would first not worry about penetration recovery and don't support restitution.

But there was a rather helpful and in-depth tutorial that showed how to deal with it. Through I will follow your suggestion if my approach to change the penetration handling from the collision detection to impulse resolution section of the code and by the way - thanks for all the help and time that you have taken to help me. I'll let you know how it goes (if you care).

One thing I learned over the past years is that with software development in general and physics development in particular is that you want to come to a working solution as fast and easy as possible. From there you want to add one feature at a time always iterating on a working solution.

You are currently seeing yourself what a pain it can be to search for a bug without having an idea where to look. If you use a smart incremental approach this helps to keep problems manageable. That is why I suggest getting the simplest problem working first and then add one feature at a time (e.g. penetration recovery and restitution).

I don't know which tutorial you are referring to so I cannot comment on this. With game physics you have the problem that there are a couple of good references by industry experts and then a bunch of students essentially rewrite these tutorial for studying purposes and quite often introduce errors reflecting their lack of understanding. So when looking at in-depth tutorial make sure they are from people who know what they are talking about.

 

1 hour ago, Dirk Gregorius said:

One ... talking about.

 

I will take your advice on board when continuing with this simulation. However, if you want to inspect the tutorial I used, it is the following link.

https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331.

That is Randy's stuff. He is on the forum here and should be able to help. I will ping him...

Hi there, Dirk's advice is trying to describe a method to debug your code. The idea is if you get a working solution, then whenever you make small changes it is easy to know what broke. From here finding problems becomes much easier.

The tutorial you posted is best used by referencing the source code in the final article. The source code is here: https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-oriented-rigid-bodies--gamedev-8032

Unfortunately I don't have time to manually step through your code to look for problems. The best thing you can try doing is to take Dirk's advice and start with a small working solution. From there you can modify the working code to look more like your own code, and replace piece by piece until something breaks. This can give you clues on where problems lay.

7 hours ago, Randy Gaul said:

Hi there, Dirk's advice is trying to describe a method to debug your code. The idea is if you get a working solution, then whenever you make small changes it is easy to know what broke. From here finding problems becomes much easier.

The tutorial you posted is best used by referencing the source code in the final article. The source code is here: https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-oriented-rigid-bodies--gamedev-8032

Unfortunately I don't have time to manually step through your code to look for problems. The best thing you can try doing is to take Dirk's advice and start with a small working solution. From there you can modify the working code to look more like your own code, and replace piece by piece until something breaks. This can give you clues on where problems lay.

Thanks for your advice, I realise that you do not have much time, but could I trouble you to explain to me when and were you deal with penetration, as I have since got the collision response working with restitution. If you would't mind, could you also explain to me how you would calculate the penetration vector for a circle-circle collision?

As at the moment, I am using this code:


PD = -(self.rad + other.rad) + math.sqrt(centDist)
angle = diff.xAxisAngle()
PDx = PD * math.cos(math.degrees(angle))
PDy = PD * math.sin(math.degrees(angle))
penetrationVec = Vector(PDx, PDy)
dP = penetrationVec.scalarMult(0.5)

self.center = (self.center).add(dP)
other.center = (other.center).subtract(dP)

While it does provide accurate enough collisions, it does however make the circles jump when I represent them on the screen. Thanks again.

I'd like to help but the question you're asking is very open ended. There isn't really a specific piece I can help you with here. I'd love to help, but it sounds like you're not sure where the problem is yet.

This topic is closed to new replies.

Advertisement