Tapping the ball

I need help making it so when the balloon is tapped it goes straight up to a certain height? How do i change edit my code to make it so when i tap the ball it goes to the height i want it to go? Thank you!

function ballf(event)
    if event.phase == “ended” then
       vx, vy = ball:getLinearVelocity()
       ball:setLinearVelocity( -vx, -vy )
    end
end

ball:addEventListener(“touch”, ballf)

function ballf(event)
        if event.phase == “ended” then
           vx, vy = ball:getLinearVelocity()
           ball:setLinearVelocity( -vx, -vy )
        end
    end

If u’re going to just tap the ball it might be better to use a “tap” event to simplify things a bit

sorry i meant touch like when you touch it the ball goes to the top of the screen no matter where you touch the ball on the screen sorry for the confusion

Hi,

I assume you are using physics.

Try this.

function ball:touch( event ) if event.phase == "began" then ball:setLinearVelocity( 0, -200 ) -- the ball will move until you stop it --ball:applyLinearImpulse( 0, 170, ball.x, ball.y ) -- or sudden push return true end end ball:addEventListener( "touch", ball ) 

Good Luck!

burhan

If u’re going to just tap the ball it might be better to use a “tap” event to simplify things a bit

sorry i meant touch like when you touch it the ball goes to the top of the screen no matter where you touch the ball on the screen sorry for the confusion

Hi,

I assume you are using physics.

Try this.

function ball:touch( event ) if event.phase == "began" then ball:setLinearVelocity( 0, -200 ) -- the ball will move until you stop it --ball:applyLinearImpulse( 0, 170, ball.x, ball.y ) -- or sudden push return true end end ball:addEventListener( "touch", ball ) 

Good Luck!

burhan