Linear Velocity Not working on transition [Code Attached]

I am developing a horizontal Ball game , In which a ball will always be running and have to jump over small hurdles. 

PROBLEM: When I jump on first platform ,On tap , the ball doesn’t bounce due to transition in the game  . 

HOW TO PLAY :

LONG JUMP --> LONG TAP 

Small JUMP --> SMALL TAP 

local physics = require "physics" physics.start() physics.setGravity( 0, 40) --physics.setDrawMode("debug") local widget = require( "widget" ) display.setStatusBar(display.HiddenStatusBar) local physicsBodyEditor = require("plugin.physicsBodyEditor") \_w = display.contentWidth; -- Get the width of the screen \_h = display.contentHeight; -- Get the height of the screen local mRand = math.random local sprite local gamegroup local particleSystem local gameoverbool=false local spritebottom=display.contentHeight-120 local tdown local collisionbool=false local transition1 local score local tiemr1 local tiemr2 local platformid=0 local platformheight local platformx local currentplatform local starcount=0 local starscoreoptions = { text = 0, x = display.contentCenterX+335, y = display.contentHeight-2\*display.contentCenterY+60, font= native.newFont("Apple Butter.ttf",60 ), width = 768, height = 100, align = "center" } function goRight() if sprite then -- sprite:setSequence("goRight") -- sprite:play() transition.to(sprite, {time=3500, delay=100, x=display.contentWidth-23, onComplete=goLeft}) end end function goLeft() -- sprite:setSequence("goLeft") -- sprite:play() transition.to(sprite, {time=3500, delay=100, x=sprite.width/2, onComplete=goRight}) end local jumpbool=true function longjump(event) if jumpbool==true and gameoverbool == false then function setcollisionon(event) collisionbool=true end timer.performWithDelay( 300, setcollisionon ) -- print("jump") if tiemr2 then timer.cancel(tiemr2) end sprite:setLinearVelocity(10,1500) jumpbool=false -- jumpbool=false end end function smalljump(event) if jumpbool==true and gameoverbool == false then function setcollisionon(event) collisionbool=true end timer.performWithDelay( 300, setcollisionon ) -- print("jump") sprite:setLinearVelocity(10,1000) jumpbool=false end end function jump(event) if event.phase == "began" then if jumpbool==true and gameoverbool == false then if tiemr1 then timer.cancel(tiemr1) end if tiemr2 then timer.cancel(tiemr2) end sprite:setLinearVelocity(0,0) -- print("jump") tiemr1=timer.performWithDelay( 180, longjump,1) tiemr2=timer.performWithDelay( 200, smalljump,1) -- function setcollisionon(event) -- collisionbool=true -- end -- -- timer.performWithDelay( 300, setcollisionon ) -- print("jump") --sprite:setLinearVelocity(10,1200) end elseif ( event.phase == "ended" or event.phase == "cancelled" ) then --jumpbool=false if tiemr1 then timer.cancel(tiemr1) end end end function gameovermethod() score.text=0 sprite.isVisible=true if gamegroup then for i=1,gamegroup.numChildren,1 do local child = gamegroup[i] transition.cancel( child ) display.remove(child) child = nil end display.remove(gamegroup) gamegroup = nil end if gameoverbggroup then for i=1,gameoverbggroup.numChildren,1 do local child = gameoverbggroup[i] transition.cancel( child ) display.remove(child) child = nil end display.remove(gameoverbggroup) gameoverbggroup = nil end main() gameoverbool=false end function gameover(event) starcount=0 currentplatform=nil platformid=0 sprite:setLinearVelocity(0,0) spritebottom=display.contentHeight-120 sprite.isVisible=false jumpbool=false if gameoverbg then display.remove(gameoverbg) gameoverbg=nil end gameoverbg = display.newRect( display.contentWidth/2,display.contentHeight/2, 768, 1024 ) gameoverbg:setFillColor( 206/255.0, 243/255.0, 255/255,0.7) gameoverbg.width=display.contentWidth gameoverbg.height=display.contentHeight if gameoverbggroup~=nil then display.remove(gameoverbggroup) gameoverbggroup=nil end gameoverbggroup = display.newGroup() local replay replay = widget.newButton({ label = "Play Again", labelColor = { default={ 0, 51/255.0, 101/255.0 }, over={ 0, 0, 0, 0.5 } }, fontSize = 60, onRelease = gameovermethod, --defaultFile ="images/play again\_1.png", }) replay.isVisible=true replay.isEnabled=false replay.x=384 replay.y=display.contentHeight-180 gameoverbggroup:insert(replay) function tapreset(event) if gameoverbggroup then if replay then replay.isEnabled=true end end end timer.performWithDelay( 1000, tapreset,1) gameoverbggroup.y=0 gameoverbggroup.alpha = 0 transition.fadeIn( gameoverbggroup, { time=1000 } ) end function addPlatforms(imagename, xvalue , yvalue) local platform platform = display.newRect( display.contentWidth/2+300,yvalue, display.contentWidth-200,40) platformid=platformid+1 platform.id=platformid -- platform.x=xvalue platform.y=yvalue gamegroup:insert( platform ) platform.myName="platform" physics.addBody( platform, "static") local hurdle = display.newCircle( display.contentWidth/2+180, platform.y-45, 20 ) hurdle.x = display.contentWidth/2+180; hurdle.y = platform.y-hurdle.height/2-45; hurdle.myName = "hurdle" physics.addBody( hurdle, "kinematic",{radius=2} ) gamegroup:insert( hurdle ) hurdle.angularVelocity = -100 -- if currentplatform==nil then -- currentplatform=platform -- end -- end local function updatelistenerforoutside( event ) if sprite and gameoverbool==false then if sprite.y\> display.contentHeight-20 then transition.cancel(sprite) -- pauseSprite() gameoverbool=true gameover() sprite:setLinearVelocity(0,0) end end end Runtime:addEventListener("enterFrame", updatelistenerforoutside) local function spawnnewrings(event) local heightsarray={} for s=gamegroup.numChildren,1,-1 do local child = gamegroup[s] if child.myName=="platform" and child.y\> display.contentHeight-30 then transition.cancel(child) display.remove(child) child=nil end end for s=gamegroup.numChildren,1,-1 do local child = gamegroup[s] if child.myName=="platform" then heightsarray[#heightsarray+1]=child.y; end end local function compare( a, b ) return a \< b -- Note "\<" as the operator end table.sort(heightsarray, compare) -- platformheight= heightsarray[1]-200 -- if platformx==display.contentWidth-150 then -- platformx=150 -- -- else -- -- platformx=display.contentWidth-150 -- -- end -- local platrandom = mRand( 1, 4 ) -- -- if platrandom==1 then -- addPlatforms("bluefly",platformx, platformheight) -- -- elseif platrandom==2 then -- addPlatforms("red",platformx,platformheight) -- elseif platrandom==3 then -- addPlatforms("blue",platformx , platformheight) -- elseif platrandom==4 then -- addPlatforms("green",platformx , platformheight) -- end -- end local function clearObject( object ) starcount=starcount+1 score.text=score.text+1 display.remove( object ) object = nil end function onCollision( event ) if ( event.phase == "began" ) then if gameoverbool==false and collisionbool==true then if event.other.myName == "platform" then if tonumber(score.text)\<(event.other.id) then jumpbool=true sprite:setLinearVelocity(0,0) score.text= score.text+1 currentplatform=event.other sprite:setLinearVelocity(0,0) transition.to(sprite,{time=600, y=sprite.y+200}) for s=gamegroup.numChildren,1,-1 do local child = gamegroup[s] if s==gamegroup.numChildren then timer.performWithDelay( 600, spawnnewrings,1) end if child.myName=="platform" or child.myName=="floor" or child.myName=="star" or child.myName=="hurdle" then transition.to(child,{time=600, y=child.y+200}) end end end elseif event.other.myName=="hurdle" then gameoverbool=true transition.cancel(sprite) transition.to(sprite,{time=400, y=1024+30, onComplete=gameover}) elseif event.other.myName~="floor" then jumpbool=true jumpbool=true sprite:setLinearVelocity(0,0) end end elseif ( event.phase == "ended" or event.phase == "cancelled" ) then collisionbool=true jumpbool=true end end function main( event ) collisionbool=true gamegroup = display.newGroup() -- Adding background in game group local gamebg = display.newRect( display.contentWidth/2,display.contentHeight/2, 768, 1024 ) gamebg:setFillColor( 0, 255/255.0,0) gamebg.width=display.contentWidth gamebg.height=display.contentHeight gamegroup:insert( gamebg ) -- Adding floor local floor floor = display.newRect(385,display.contentHeight-50,display.contentWidth,100) floor.x=385 floor.y=display.contentHeight-50 gamegroup:insert( floor ) floor.myName="floor" floor.isSensor=true physics.addBody( floor, "static",{bounce = 0.0, friction = 10}) if(sprite) then physics.removeBody(sprite) display.remove(sprite) sprite=nil end sprite = display.newCircle( 140, display.contentHeight-120, 20 ) sprite:setFillColor( 0.5 ) sprite.x = 140 sprite.y =display.contentHeight-120 physics.addBody(sprite,"dynamic",{ density=1, friction=0.3, bounce=0.50}) sprite.angularVelocity=0 sprite.isFixedRotation=true sprite.isBullet = true sprite:addEventListener("collision", onCollision) if score then display.remove(score) score=nil end score = display.newText(starscoreoptions) score:setFillColor(1, 0, 0,1) addPlatforms("blue",display.contentWidth-150, display.contentHeight-250) platformheight= display.contentHeight-1450 platformx=150 function tapjump(event) jumpbool=true end timer.performWithDelay( 100, tapjump,1) goRight() end Runtime:addEventListener("touch", jump) main()

Don’t have time to look through the code but if you have “ball1” in transition with “transition.to” and you try do something with physics to it; it wont work. When using “transition.to” the physics for that object if temporarily disabled. 

Instead of using transition.to, try setLinearVelocity():

https://docs.coronalabs.com/api/type/Body/setLinearVelocity.html

Don’t have time to look through the code but if you have “ball1” in transition with “transition.to” and you try do something with physics to it; it wont work. When using “transition.to” the physics for that object if temporarily disabled. 

Instead of using transition.to, try setLinearVelocity():

https://docs.coronalabs.com/api/type/Body/setLinearVelocity.html