Apply velocity to only one axis (X or Y) in Box2d?

Go To StackoverFlow.com

0

I am trying to make a player jump in my game when it touches a platform, but at the same time it should be controlled by the Accelerometer to move left and right. So, I was thinking about applying linear velocity on the Y axis in the contact listener to make it jump, while applying linear velocity on the X axis when the Accelerometer changes its value.

The problem is when I use the setLinearVelocity method, it sets the values for the Velocity on both axis. As a result, the player doesn't jump because the accelerometer changes the velocity value on the Y axis.

Does any one have an idea how to do this?

2012-04-05 21:36
by Ayham


2

b2Vec2 v = body->GetLinearVelocity();
v.x = ...;
body->SetLinearVelocity( v );
2012-04-06 17:40
by iforce2d
I did something similar: Vector2 v = new Vecto2(body.getLinearVelocity().x, newYVelocityFloat) - Lokiare 2012-04-12 17:16
Ads