Hi !
I'm working on a new game and I wanted to create, using box2D, some Attract Points.
I mean points that grab the bodies within a certain area (a circle) so that they don't move once caught.
For that I use a sensor static body which shape is a circle and for each collision with the circle, I calculate a force aimed to the center of this circle as below :
But still, it doesn't work… When I release a circle shaped body above this point it is affected by the force I apply but it still goes down in the end.
What am I doing wrong ?
Thanks !
I'm working on a new game and I wanted to create, using box2D, some Attract Points.
I mean points that grab the bodies within a certain area (a circle) so that they don't move once caught.
For that I use a sensor static body which shape is a circle and for each collision with the circle, I calculate a force aimed to the center of this circle as below :
Code:
Contact c = ce.contact;
Body b = null;
if(c.isTouching())
{
if(c.getFixtureA().getBody() != m_body) b = c.getFixtureA().getBody();
else if(c.getFixtureB().getBody() != m_body) b = c.getFixtureB().getBody();
Vec2 dir = (new Vec2(m_x, m_y)).add(b.getPosition().negateLocal());
dir = dir.mul(m_f/m_r); //m_f and m_r are forces and radius set.
b.applyForce(dir, b.getPosition());
}
Body b = null;
if(c.isTouching())
{
if(c.getFixtureA().getBody() != m_body) b = c.getFixtureA().getBody();
else if(c.getFixtureB().getBody() != m_body) b = c.getFixtureB().getBody();
Vec2 dir = (new Vec2(m_x, m_y)).add(b.getPosition().negateLocal());
dir = dir.mul(m_f/m_r); //m_f and m_r are forces and radius set.
b.applyForce(dir, b.getPosition());
}
But still, it doesn't work… When I release a circle shaped body above this point it is affected by the force I apply but it still goes down in the end.
What am I doing wrong ?
Thanks !