Hy i have problem with top-down physics(actually with friction...) in jBox2D.
this is mine "callback" for updating physics. it is called every time before step.
It acts very weird when hit by another object or i apply force on it . It stops fast. and then moves very slow but not stopping.
thx for help.
this is mine "callback" for updating physics. it is called every time before step.
Code:
protected void update(float dt)
{
Vec2 pos = _body.getPosition();
Mat22 rot = new Mat22(_body.getAngle());
float mass = _body.getMass();
float I = _body.getInertia();
float fk_kinetic = _pm.getGroundFriction_Kinetic(pos);
float fk_static = _pm.getGroundFriction_Static(pos);
{
Vec2 v_0 = _body.getLinearVelocity();
Vec2 a = v_0.mul(-1/dt);
float sa = a.length(); //scalar accleration
float a_s = _pm.getGravity() * fk_static;//Static max acceleration
float a_k = _pm.getGravity() * fk_kinetic;//Kinetic max acceleration
float ar = sa * (1-fk_kinetic);
if(sa>a_s)
{
ar = sa-a_k;
}
if(sa>0.0)
_body.applyForce(a.mul((ar * mass)/sa),_body.getWorldCenter());
}
{
float o_0 = _body.getAngularVelocity();
float a = -o_0 / dt;
_body.applyTorque(I * a * (1-fk_kinetic));
}
}
{
Vec2 pos = _body.getPosition();
Mat22 rot = new Mat22(_body.getAngle());
float mass = _body.getMass();
float I = _body.getInertia();
float fk_kinetic = _pm.getGroundFriction_Kinetic(pos);
float fk_static = _pm.getGroundFriction_Static(pos);
{
Vec2 v_0 = _body.getLinearVelocity();
Vec2 a = v_0.mul(-1/dt);
float sa = a.length(); //scalar accleration
float a_s = _pm.getGravity() * fk_static;//Static max acceleration
float a_k = _pm.getGravity() * fk_kinetic;//Kinetic max acceleration
float ar = sa * (1-fk_kinetic);
if(sa>a_s)
{
ar = sa-a_k;
}
if(sa>0.0)
_body.applyForce(a.mul((ar * mass)/sa),_body.getWorldCenter());
}
{
float o_0 = _body.getAngularVelocity();
float a = -o_0 / dt;
_body.applyTorque(I * a * (1-fk_kinetic));
}
}
It acts very weird when hit by another object or i apply force on it . It stops fast. and then moves very slow but not stopping.
thx for help.