Hi everyone. I'm currently working on a project using libgdx which has Box2D implemented. I'm not sure if this bug will happen without the port, but here goes:
When I make my body move in the X-axis and subsequently jump in the Y-axis (i tried both applyforce and applyLinearImpulse), it seems that my X velocity will reset on the next tick. Is there any particular reason for this?
here are some snippets of my code(in java):
I have (hopefully temporarily) replaced the last line with:
and it works exactly as I wanted, just that I have to manage speed myself. However, I don't really enjoy replacing code without knowing what went wrong in the first place. Anyone care to shed some light on this?
Thanks,
Faylar
When I make my body move in the X-axis and subsequently jump in the Y-axis (i tried both applyforce and applyLinearImpulse), it seems that my X velocity will reset on the next tick. Is there any particular reason for this?
here are some snippets of my code(in java):
Code:
Vector2 temp = mPhyObj.getWorldCenter();
if ( Global.gInputManager.CheckTopEvent(cInputEvent.INPUTTYPE.TOUCHDOWN))
{
Gdx.app.log("HERO", "TAPPED");
if ( Global.gInputManager.GetTopEvent().mTouchX > 100 )
{
Gdx.app.log("HERO", "JUMP: " + mPhyObj.getLinearVelocity().x);
//mPhyObj.applyForce(0.f, 10000.f, mPhyObj.getPosition().x, mPhyObj.getPosition().y);
mPhyObj.applyLinearImpulse(0.f, 1000.f, temp.x, temp.y);
}
}
Gdx.app.log("HERO", "NORM: " + mPhyObj.getLinearVelocity().x);
mPhyObj.applyLinearImpulse(0.01f, 0.f, temp.x, temp.y);
if ( Global.gInputManager.CheckTopEvent(cInputEvent.INPUTTYPE.TOUCHDOWN))
{
Gdx.app.log("HERO", "TAPPED");
if ( Global.gInputManager.GetTopEvent().mTouchX > 100 )
{
Gdx.app.log("HERO", "JUMP: " + mPhyObj.getLinearVelocity().x);
//mPhyObj.applyForce(0.f, 10000.f, mPhyObj.getPosition().x, mPhyObj.getPosition().y);
mPhyObj.applyLinearImpulse(0.f, 1000.f, temp.x, temp.y);
}
}
Gdx.app.log("HERO", "NORM: " + mPhyObj.getLinearVelocity().x);
mPhyObj.applyLinearImpulse(0.01f, 0.f, temp.x, temp.y);
I have (hopefully temporarily) replaced the last line with:
Code:
mPhyObj.setLinearVelocity( mSpeed , mPhyObj.getLinearVelocity().y);
mSpeed += mAcceleration *dt ;
mSpeed += mAcceleration *dt ;
and it works exactly as I wanted, just that I have to manage speed myself. However, I don't really enjoy replacing code without knowing what went wrong in the first place. Anyone care to shed some light on this?
Thanks,
Faylar