I am new to the Corona/lua language and although most of what I have developed is working as expected I have one problem that I cannot resolve.
I have a single ‘cue’ ball that is sent down the screen which has gravity set to (0,0) since it is a horizontal playing surface. When the cue ball stops I create a new ball in the same location with the same properties as the cue ball and add it to the physics engine. I then move the cue ball back to the start. This all works fine. The problem arrises when the new cue ball hits the new stationary ball. The cue ball acts as it should by eventually stopping, but the other ball just keeps moving. It does not slow down.
Here is the code i use to create the cue ball (only used once)
-- Create cueball
local ballBody = { density=0.8, friction=0.2, bounce=0.5, radius=15 }
local cueball = display.newImage( "ball\_silver.png" )
cueball.x = \_W-240; cueball.y = 900
-- give the cue ball the correct physics
physics.addBody( cueball, ballBody )
cueball.linearDamping = 0.3
cueball.angularDamping = 0.8
cueball.isBullet = true -- force continuous collision detection, to stop really fast shots from passing through other balls
cueball.id = "cue"
Here is the code i use to create the new ball (called in a function each time the cue ball stops)
-- display a new ball where the cue ball ended up
local ball = display.newImage( "ball\_silver.png" )
ball.linearDamping = 5.0
ball.angularDamping = 1.0
local newBallBody = { density=2.0, friction=2.0, bounce=0.2, radius=15 }
physics.addBody( ball, newBallBody )
ball.x = cueball.x;
ball.y = cueball.y;
ball.id = "score"
Can anyone see what I am doing wrong? [import]uid: 62935 topic_id: 10262 reply_id: 310262[/import]