when i use this code:
private void InitContactCallbacks() {
ContactCallback contactPlayerPongBall = new ContactCallback() {
public boolean adjustContact( PendingContact c ) {
boolean case1 = PongBalls.contains(c.getNode1());
boolean case2 = PongBalls.contains(c.getNode2());
if ((
case1 && c.getNode2() == Player )|| (
case2 && c.getNode1() == Player )){
if(case1){
doColisionPlayerPongBall((DynamicPhysicsNode)c.getNode1(), c.getNode2());
}
else{
doColisionPlayerPongBall((DynamicPhysicsNode)c.getNode2(), c.getNode1());
}
//return true;
}
return false;
}
};
getPhysicsSpace().getContactCallbacks().add( contactPlayerPongBall );
}
private void doColisionPlayerPongBall(DynamicPhysicsNode ball, PhysicsNode other) {
Vector3f force = ball.getLocalTranslation();
force = force.subtract(other.getLocalTranslation());
force = force.mult(-50);
ball.addForce(force);
System.out.println(force);
}
the output is always
print the force twice after first collision
and then randomly print one or twice.
i have tried to remove one of the conditions from the if
if ((
case1 && c.getNode2() == Player )|| (
case2 && c.getNode1() == Player )){
but it haven't worked :/
sometimes the ball get a little impulse, sometimes it gets a huge impulse :/
any light to the situation?