A
A
Andrey Andryushchenko2015-02-28 14:03:52
Java
Andrey Andryushchenko, 2015-02-28 14:03:52

How to implement particle attraction on LibGDX Box2D?

I'm writing a game using the box2d physics engine, which is part of libGDX. It is necessary to make a simulation that the particles are attracted to each other according to the law of universal gravitation. I decided to solve this problem in the following way: between each two particles, I create a DistanceJoint. They are attracted, but not in the right way. According to the law of universal gravitation, the GREATER the distance, the LESS the force of attraction. But in my case, the opposite is true. Now the question is how to make the force of attraction of particles depend inversely proportionally? Maybe you need to use a different Joint, or some completely different class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Petrov, 2015-03-01
@delphikettle

I don’t know why the fuck it’s necessary, but okay. An object of the Body class has an applyForce method. Consider the force vector yourself (if I understand correctly, it will be something like a difference in positions) for each body, the point of application is the center of mass (it seems that there was even a special method to apply to it immediately). This operation will need to be repeated as long as the force acts.
Here is another read:
iforce2d.net/b2dtut/forces
Well, something in theory in general. The choice is huge.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question