Sri Krishna Paritala
Sri Krishna Paritala

Reputation: 617

LibGdx Setting Velocity

How can I set Linear Velocity in only X direction without effecting the motion of Y Direction to a body in LIBGDX Box2D. I applied an impulse to the body to make it jump now I want to move it towards right or left I tried applying the following method:

setLinearVelocity(Vector2)

But it is stopping the vertical motion. Thanks

Upvotes: 0

Views: 1855

Answers (1)

noone
noone

Reputation: 19776

Just retrieve the current velocity via the getter, manipulate it and set the new one.

Vector2 velocity = body.getLinearVelocity().cpy();
velocity.set(500, velocity.y);
body.setLinearVelocity(velocity);

Upvotes: 4

Related Questions