I am trying to simlate some molecules moving in Solar 2d. All I wanted was a number of independent molecules which bounce off each other elastically and against the walls of the container changing direction as they collide but keeping the same velocity until the simulation ends.
the simulation creates a boundary box (static, bounce = 1, friction = 0) and then creates molecules with a random start location inside the box with properties dynamic, bounce = 1 and friction = 0 . I give all the objects the same linear velocity (100,100).
My assumptions from the documentation is that those particles would bounce off each other randomly until the simulation stops.
What I get is particles that start of perfectly elastic but gradually (one by one ) the particles become horizontal bounces along the top of hte box and gradually stop.
I cant see what is wrong. Any ideas?
for interest here is my code:
– Create “walls” around screen
local cellwall = display.newLine( mainGroup, 60,80, 260,80, 260,280, 60,280, 60,80 )
physics.addBody( cellwall, “static”, { bounce=1, friction=0.0 })–filter=borderCollisionFilter } )
local Membrane = display.newLine( mainGroup,60,180,260,180 )
physics.addBody( Membrane, “static”, { bounce=1, friction=0.0 })–filter=borderCollisionFilter } )
– Create blue molecules in top
for b = 1,4 do
local blueMolecule = display.newImageRect(“sodium.png”,moleculeSize,moleculeSize)
repeat
xpos = math.random(65,255)
ypos = math.random(85,155)
until xpos~= ypos
blueMolecule.x = xpos
blueMolecule.y = ypos
physics.addBody( blueMolecule, “dynamic”, { bounce=1.0, friction=0, radius=1}) --filter=blueCollisionFilter } )
blueMolecule.isFixedRotation = false
blueMolecule:
blueMolecule:setLinearVelocity(100,100)
end