How do you change only x or only y velocity?

Thanks for reading.

How do you change only one component e.g. x direction of the velocity?

I have tried to use setLinearVelocity(vx, nil) to set only x direction. However, this would affect the current y direction motion.

I have also tried to first getLinearVelocity to get vy and then setLinearVelocity(vx, vy). However, this would also affect the current y direction motion.

What I want to do is that: An object is jumping up and down repeatedly, and it would follow the mouse cursor to either jump leftward or rightward. The further the mouse cursor, the higher the x direction velocity.

Thanks. [import]uid: 12769 topic_id: 7865 reply_id: 307865[/import]

I figured out that it’s not possible to change one component without interfering the other one, so I now use my own velocity and gravity logic. [import]uid: 12769 topic_id: 7865 reply_id: 28729[/import]

Actually you can : just save the current velocity, and change the one you require

    local  currentVx, currentVy = character:getLinearVelocity()

    character:setLinearVelocity( newVx , currentVy )

Actually you can : just save the current velocity, and change the one you require

    local  currentVx, currentVy = character:getLinearVelocity()

    character:setLinearVelocity( newVx , currentVy )