Bullet Pong Physics Issues

I’ve been running into too many issues at hand and wonder if anyone has any tips here.

  • Ball, Paddle and Walls have 0 friction, 1.0 restitution (bounce), there is also no gravity in the world. This should mean the ball will never stop boucing, right? Nope… The ball will eventually stop. The paddles are kinematic, the walls are static. I’ve tried messing with angular damping, and even increasing the restitution, but either the ball speeds up too fast or slow down at some point.
  • If the paddle is moving while impacting with ball, the ball will slow down, I assume this is due to transfer of motion. This happens to a slow moving ball, increasing the speed of the balls causes less of an issue.
  • The paddles are taller than the balls and given enough speed the ball will, at some point, become airborne.

After each paddle hit I apply an impluse to keep the ball moving and slowly increase the ball’s overall velocity. I use the paddle’s center position to apply an additional angle to the ball so that does not keep boucing in the same position. The impact code is in Kotlin but should be readable on what I am doing:

override fun prePhysicsTick(space: PhysicsSpace, tpf: Float) {
    val centerOfBall = control.physicsLocation
    var impulse = Vector3f.ZERO

    ghostObject?.overlappingObjects?.forEach { collisionObj ->
        if (collisionObj is PhysicsRigidBody && collisionObj is PaddleControl) {
            val centerOfPaddle = collisionObj.physicsLocation
            //-- Get the local location from ball and paddle
            centerOfPaddle.subtractLocal(centerOfBall)
            centerOfPaddle.normalizeLocal()
            //-- Get the up / down position to decide on the force to apply
            val z = centerOfPaddle.getZ()
            val zForce = -1 * z / 100
            val xForce = if (centerOfPaddle.getX() > 0) -0.08f else 0.08f
            impulse = Vector3f(xForce, 0f, zForce)
        }
    }

    control.applyImpulse(impulse, Vector3f.ZERO)
}

The full code for that specific collision is here: PongJM3/PaddleCollision.kt at master · joseph-montanez/PongJM3 · GitHub

The code that keeps the ball bouncing at a faster speed is the following line:

val xForce = if (centerOfPaddle.getX() > 0) -0.08f else 0.08f

Overall I am thinking is dropping using the physics engine to do what is extremely basic feature, and only using Bullet for collision detection.Althought at that point I can drop the usage of bullet since all I need is AABB collision dection which jMonkeyEngine supports on its own.

1 Like

Why on earth would you use a physics engine to create pong behavior?

1 Like

I think it’s a valid design choice. To make sure that angles in/out are calculated for all ‘bounces’.

1 Like

Plus, I seem to recall that it has buffs that makes the balls act as if they are drawn downwards. Which with physics is just applying another force on top of already existing forces.

1 Like

Thats integrating vectors for two dimensions… Seriously, you don’t need bullet, physx or anything like that to do that.

1 Like

@normen didn’t say anything specific :stuck_out_tongue: but it is overkill to use Bullet for a basic feature, but I was using it as a learning exercise (learning Bullet) than a pratical application. But, its making the game unplayable and I am probably better off spending my time learning deeper concepts in jMonkeyEngine. That said some of issues are valid no matter if it was pong or not. For example the ball bouncing issue. I cannot set the ball’s mass to zero as it will never move, it becomes “static”. The mass may very well be the reason why the ball does not continue to bounce. I probably will need to dig into Bullets source code to see how its calculating against restitution this way I can derive a forumla on how much restitution is needed in order to never stop bouncing, based on the mass (or whatever is causing this issue) of two objects.

Overall the ball should not have stopped bouncing if the restitution was 1 between two objects and other factors such as gravity does not exist and mesh deformation.

1 Like