Help With Controlling Sprite's Jump Height

I’m having trouble making the sprite go up in the style of jetpack joyride where if I let go of the screen the sprite will fall. 

I can make the sprite jump higher with this code

 if(onGround) then
                monster.accel = monster.accel + 26
            end

but I can’t make the touch like jetpack joyride where I go up until I release my finger.

&nbsp; display.setStatusBar(display.HiddenStatusBar) local sprite = require("sprite") &nbsp; local backbackground = display.newImage("background.png") backbackground.x = 240 backbackground.y = 160 &nbsp; local backgroundfar = display.newImage("bgfar1.png") backgroundfar.x = 480 backgroundfar.y = 160 &nbsp; local backgroundnear1 = display.newImage("bgnear2.png") backgroundnear1.x = 240 backgroundnear1.y = 160 &nbsp; local backgroundnear2 = display.newImage("bgnear2.png") backgroundnear2.x = 760 backgroundnear2.y = 160 &nbsp; local blocks = display.newGroup() local player = display.newGroup() local screen = display.newGroup() &nbsp; local groundMin = 420 local groundMax = 340 local groundLevel = groundMin local speed = 5 &nbsp; for a = 1, 8, 1 do &nbsp;&nbsp;&nbsp;&nbsp;isDone = false &nbsp;&nbsp;&nbsp;&nbsp;numGen = math.random(2) &nbsp;&nbsp;&nbsp;&nbsp;local newBlock &nbsp;&nbsp;&nbsp;&nbsp;print (numGen) &nbsp;&nbsp;&nbsp;&nbsp;if(numGen == 1 and isDone == false) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newBlock = display.newImage("ground1.png") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isDone = true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if(numGen == 2 and isDone == false) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newBlock = display.newImage("ground2.png") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isDone = true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if(numGen == 3 and isDone == false) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newBlock = display.newImage("ground3.png") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isDone = true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if(isDone == false) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newBlock = display.newImage("ground1.png") &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;newBlock.name = ("block" .. a) &nbsp;&nbsp;&nbsp;&nbsp;newBlock.id = a &nbsp;&nbsp;&nbsp;&nbsp;newBlock.x = (a \* 79) - 79 &nbsp;&nbsp;&nbsp;&nbsp;newBlock.y = groundLevel &nbsp;&nbsp;&nbsp;&nbsp;blocks:insert(newBlock) end &nbsp; --create our sprite sheet local spriteSheet = sprite.newSpriteSheet("monsterSpriteSheet1.png", 100, 100) local monsterSet = sprite.newSpriteSet(spriteSheet, 1, 7) sprite.add(monsterSet, "running", 1, 6, 600, 0) sprite.add(monsterSet, "jumping", 7, 7, 1, 1) &nbsp; --set the different variables we will use for our monster sprite --also sets and starts the first animation for the monster local monster = sprite.newSprite(monsterSet) monster:prepare("running") monster:play() monster.x = 110 monster.y = 200 --these are 2 variables that will control the falling and jumping of the monster monster.gravity = -6 monster.accel = 0 &nbsp; --rectangle used for our collision detection --it will always be in front of the monster sprite --that way we know if the monster hit into anything local collisionRect = display.newRect(monster.x + 36, monster.y, 1, 70) collisionRect.strokeWidth = 1 collisionRect:setFillColor(140, 140, 140) collisionRect:setStrokeColor(180, 180, 180) collisionRect.alpha = 0 &nbsp; --used to put everything on the screen into the screen group --this will let us change the order in which sprites appear on --the screen if we want. The earlier it is put into the group the --further back it will go screen:insert(backbackground) screen:insert(backgroundfar) screen:insert(backgroundnear1) screen:insert(backgroundnear2) screen:insert(blocks) screen:insert(monster) screen:insert(collisionRect) &nbsp; --the update function will control most everything that happens in our game --this will be called every frame(30 frames per second in our case(the default in corona)) local function update( event ) &nbsp;&nbsp;&nbsp;&nbsp;updateBackgrounds() &nbsp;&nbsp;&nbsp;&nbsp;updateSpeed() &nbsp;&nbsp;&nbsp;&nbsp;updateMonster() &nbsp;&nbsp;&nbsp;&nbsp;updateBlocks() &nbsp;&nbsp;&nbsp;&nbsp;checkCollisions() end &nbsp; function checkCollisions() &nbsp; &nbsp; &nbsp; &nbsp; --boolean variable so we know if we were on the ground in the last frame &nbsp;&nbsp;&nbsp;&nbsp;wasOnGround = onGround &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--checks to see if the collisionRect has collided with anything. This is why it is lifted off of the ground &nbsp;&nbsp;&nbsp;&nbsp;--a little bit, if it hits something we will want our monster to do something... like die! This is why we don't want it &nbsp; &nbsp; &nbsp; &nbsp; --hitting the ground, it wouldn't make sense for the monster to die everything he touched the ground. We check this by cycling through &nbsp;&nbsp;&nbsp;&nbsp;--all of the ground pieces in the blocks group and comparing their x and y coordinates to that of the collisionRect &nbsp;&nbsp;&nbsp;&nbsp;for a = 1, blocks.numChildren, 1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(collisionRect.y - 10\> blocks[a].y - 170 and blocks[a].x - 40 \< collisionRect.x and blocks[a].x + 40 \> collisionRect.x) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;speed = 0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--this is where we check to see if the monster is on the ground or in the air, if he is in the air then he can't jump(sorry no double &nbsp;&nbsp;&nbsp;&nbsp;--jumping for our little monster, however if you did want him to be able to double jump like Mario then you would just need &nbsp;&nbsp;&nbsp;&nbsp;--to make a small adjustment here, by adding a second variable called something like hasJumped. Set it to false normally, and turn it to &nbsp;&nbsp;&nbsp;&nbsp;--true once the double jump has been made. That way he is limited to 2 hops per jump. &nbsp;&nbsp;&nbsp;&nbsp;--Again we cycle through the blocks group and compare the x and y values of each. &nbsp;&nbsp;&nbsp;&nbsp;for a = 1, blocks.numChildren, 1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(monster.y \>= blocks[a].y - 170 and blocks[a].x \< monster.x + 60 and blocks[a].x \> monster.x - 60) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster.y = blocks[a].y - 171 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onGround = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onGround = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end end &nbsp; function updateMonster() &nbsp;&nbsp;&nbsp;&nbsp;--if our monster is jumping then switch to the jumping animation &nbsp;&nbsp;&nbsp;&nbsp;--if not keep playing the running animation &nbsp;&nbsp;&nbsp;&nbsp;if(onGround) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(wasOnGround) then &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster:prepare("running") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster:play() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster:prepare("jumping") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster:play() &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if(monster.accel \> 0) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster.accel = monster.accel - 1 &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--update the monsters position, accel is used for our jump and &nbsp;&nbsp;&nbsp;&nbsp;--gravity keeps the monster coming down. You can play with those 2 variables &nbsp;&nbsp;&nbsp;&nbsp;--to make lots of interesting combinations of gameplay like 'low gravity' situations &nbsp;&nbsp;&nbsp;&nbsp;monster.y = monster.y - monster.accel &nbsp;&nbsp;&nbsp;&nbsp;monster.y = monster.y - monster.gravity &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--update the collisionRect to stay in front of the monster &nbsp;&nbsp;&nbsp;&nbsp;collisionRect.y = monster.y end &nbsp; --this is the function that handles the jump events. If the screen is touched on the left side --then make the monster jump function touched( event ) &nbsp;&nbsp;&nbsp;&nbsp;if(event.phase == "began") then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(event.x \< 241) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(onGround) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monster.accel = monster.accel + 26 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end end &nbsp; function updateSpeed() &nbsp;&nbsp;&nbsp;&nbsp;speed = speed + .05 end &nbsp; function updateBlocks() &nbsp;&nbsp;&nbsp;&nbsp;for a = 1, blocks.numChildren, 1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(a \> 1) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newX = (blocks[a - 1]).x + 79 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newX = (blocks[8]).x + 79 - speed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((blocks[a]).x \< -40) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(blocks[a]).x, (blocks[a]).y = newX, (blocks[a]).y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(blocks[a]):translate(speed \* -1, 0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;end end &nbsp; function updateBackgrounds() &nbsp;&nbsp;&nbsp;&nbsp;--far background movement &nbsp;&nbsp;&nbsp;&nbsp;backgroundfar.x = backgroundfar.x - (speed/55) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--near background movement &nbsp;&nbsp;&nbsp;&nbsp;backgroundnear1.x = backgroundnear1.x - (speed/5) &nbsp;&nbsp;&nbsp;&nbsp;if(backgroundnear1.x \< -239) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backgroundnear1.x = 760 &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;backgroundnear2.x = backgroundnear2.x - (speed/5) &nbsp;&nbsp;&nbsp;&nbsp;if(backgroundnear2.x \< -239) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backgroundnear2.x = 760 &nbsp;&nbsp;&nbsp;&nbsp;end end &nbsp; --this is how we call the update function, make sure that this line comes after the actual function or it will not be able to find it --timer.performWithDelay(how often it will run in milliseconds, function to call, how many times to call(-1 means forever)) timer.performWithDelay(1, update, -1) Runtime:addEventListener("touch", touched, -1)