I have a juggling soccer ball game I am playing around with. So far everything looks good, the only issue I am having is the actual juggling of the ball. The idea is the user touches the ball and the ball bounces up as if it was kicked, on its way down the user touches it again and the balls kicks up again. My problem is when I touch the ball it kicks up high, but then on its way down when I touch it again, it only kicks up a tiny bit, and the balls keeps spinning around. Pretty sure it has something to do with LinearImpulse
Here is my code.
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here local physics = require('physics'); physics.start(); --physics.setDrawMode( "hybrid" ); local width = display.viewableContentWidth; local height = display.viewableContentHeight; local centerX = width/2; local centerY = height/2; local speed = 3; local bg = display.newImage( "img/field.jpg" ,centerX,centerY); bg.height = height+200; bg.width = width; local ground = display.newRect( centerX, 470, width, 50 ) ground.alpha = .3; physics.addBody( ground, "static", { density=3.0, friction=0.5, bounce=0.3 } ); local leftWall = display.newRect( -15, centerY, 30, height\*2 ); leftWall.alpha = 0; physics.addBody( leftWall, "static", { density=3.0, friction=0.5, bounce=0.1 } ) local rightWall = display.newRect( width+20, centerY, 30, height\*2 ); rightWall.alpha = 1; physics.addBody( rightWall, "static", { density=3.0, friction=0.5, bounce=0.1 } ) local topWall = display.newRect( centerX, -50, width, 10 ); topWall.alpha = 0; physics.addBody( topWall, "static", { density=3.0, friction=0.5, bounce=0.1 } ) local ball = display.newImage( "img/soccerBall.png",centerX,centerY ); ball.width = 60; ball.height = 60; physics.addBody( ball, "dynamic", { density=3.0, friction=0.5, bounce=.3, radius = 30}); local function kickBall(event) if event.phase == "began" then print( "Began" ); print (ball.y) if ball.y then ball:applyLinearImpulse( 0, -120, event.x, event.y ) end end if event.phase == "ended" then print( "Ended" ); end end ball:addEventListener( "touch", kickBall );
