jme3 - bouncing balls

3 replies [Last post]
heftimus's picture
Offline
Joined: 06/23/2012

I need to create a 3d hollow box containing 3 balls that have frictionless collision with each other and the sides of the box.  I also need to have the coords of each sphere to write to a text file once per second.

Offline
Joined: 12/13/2010
To do something like this in

To do something like this in env3d, you'll have to use some basic vector mathematics.  For each ball object, you need to store a 3d vector with components x, y, and z representing the current direction of the ball.  Every frame, you will add the components of the 3d direction vector to the x, y, and z component of the object, making it move.

 

When a collision happens, simply negate some components of the direction vector to make it change direction.

 

Every 30 frames, simply write out the x,y, and z fields of each ball to a text file.