Hi all,
I'm new to box2d, and i'm making games for android. There is something i want to ask,
I want to create an object which will pull other object, something like gravity / magnetic field,
while there is world gravity also so they will affecting each other.
I calculate how much force applied to other object like this:
Code:
Vec2 position = source.getPosition();
Vec2 position2 = target.getPosition();
float range = spacing(position.x - position2.x, position.y - position2.y); //method to calculate range, just simple pythagoras
if(range <= FIELD_RADIUS) {
Vec2 force = new Vec2(position.x-position2.x, position.y-position2.y);
force.normalize(); //force direction always point to source
force.mul(target.getMass * 10 * (FIELD_RADIUS-range) / FIELD_RADIUS);
target.applyForce(force, target.getWorldCenter());
}
I can't find what's wrong with this code, but no matter how much force I applied, the object doesn't seems to be pulled by the source.
Even if i change the force magnitude to 10000 it won't pull the object, unless i set the world gravity to zero. strange...
So I think maybe i use the applyForce not correctly, can any of you give me suggestion / solution?
Also, i want to know the difference between getWorldCenter and getPosition.
Thanks in advance.