i have a problem with the velocity change of my body. Normaly the linearVelocity is 3f, and when the body collides with a wall the velocity shoud change at -3f. But when it does it goes around 0.
Here's the code:
private void createPlayer(){
...
bdef.velocity.set(-3f,0);
...
}
private void render(){
...
world.step(V.STEP, V.VELOCITYITERATIONS, V.POSITIONITERATIONS);
if(cHandler.changeVelocity())
ball.getBody().setLinearVelocity(-ball.getBody().getLinearVelocity().x, 0);
...
}
i've already try it in beginContact, endContact, presolve and endsolve but always it is about 0.
And when i put the collision detection in beginContact and set it manually to -3f then it is -3f but the jumping does not work anymore correctly, i mean the gravity do not grab the ball anymore to the ground.
when i set it manually:
if(cHandler.changeVelocity()){
ball.getBody().setLinearVelocity(-3f, 0);
}
the log before:
velocityX: 3.0022564 velocityY: -5.261436
and after:
velocityX: -3.0 velocityY: 0.0
that mean i will that the body move continius right and after colliding continius left till a new collide..
p.s the world gravity is (0, -10)
i hope you can help me.
Thanks!
Here's the code:
private void createPlayer(){
...
bdef.velocity.set(-3f,0);
...
}
private void render(){
...
world.step(V.STEP, V.VELOCITYITERATIONS, V.POSITIONITERATIONS);
if(cHandler.changeVelocity())
ball.getBody().setLinearVelocity(-ball.getBody().getLinearVelocity().x, 0);
...
}
i've already try it in beginContact, endContact, presolve and endsolve but always it is about 0.
And when i put the collision detection in beginContact and set it manually to -3f then it is -3f but the jumping does not work anymore correctly, i mean the gravity do not grab the ball anymore to the ground.
when i set it manually:
if(cHandler.changeVelocity()){
ball.getBody().setLinearVelocity(-3f, 0);
}
the log before:
velocityX: 3.0022564 velocityY: -5.261436
and after:
velocityX: -3.0 velocityY: 0.0
that mean i will that the body move continius right and after colliding continius left till a new collide..
p.s the world gravity is (0, -10)
i hope you can help me.
Thanks!