Hi All,
I am using LibGdx to make a small android app using Box2D. My problem is quite odd. The idea is that if I touch the screen (or use mouse) then an impluse is applied to the player to move them toward to touch position:
This does work, however if I use this system for about 30 seconds, the player's velocity's y component either slowly changes to around +190 or - 190. I can apply a force in the other direction by touching the other direction, this slightly affects the velocity but then it just changes back to +- 190.
I have no idea what is going on, does anyone have any suggestions?
Regards,
Alex
I am using LibGdx to make a small android app using Box2D. My problem is quite odd. The idea is that if I touch the screen (or use mouse) then an impluse is applied to the player to move them toward to touch position:
Code: Select all
if(Gdx.input.isTouched())
{
Vector2 delta = new Vector2(Gdx.input.getX() - player.getWorldCenter().x, Gdx.input.getY() - player.getWorldCenter().y);
double angle = Math.atan2(delta.y, delta.x);
Vector2 direction = new Vector2((float)Math.cos(angle), (float)-Math.sin(angle));
float power = 100f;
Vector2 impulse = new Vector2(power * direction.x, power * direction.y);
Vector2 point = player.getWorldCenter();
player.applyLinearImpulse(impulse, point, true);
}This does work, however if I use this system for about 30 seconds, the player's velocity's y component either slowly changes to around +190 or - 190. I can apply a force in the other direction by touching the other direction, this slightly affects the velocity but then it just changes back to +- 190.
I have no idea what is going on, does anyone have any suggestions?
Regards,
Alex