Ball constantly spins when supposed to react to touch and move left or right

Im testing the tutorial online (Make a game in 8 minutes) and I entered this code -

local ball = display.newImage(“super_ball.png”)
ball.x = 40
ball.y = -1
ball:setReferencePoint( display.CenterReferencePoint )
physics.addBody( ball, {bounce=0.1, radius=23, friction=0.8} )
function moveBall(event)
ball:applyLinearImpulse( 0, -0.05, event.x, event.y )
end

ball:addEventListener( “touch”, moveBall)

It works for the most part, but if I hit the right side of the ball, it doesn’t go left, it just spins faster and faster each time I touch it, and likewise with the left side.

Please help! [import]uid: 39628 topic_id: 7510 reply_id: 307510[/import]

but you are applying a linear force upwards from the point you touched… why would it go left?
[import]uid: 6645 topic_id: 7510 reply_id: 26651[/import]

http://www.youtube.com/watch?v=Idrug4vHSgg

watch that video and scroll to 4:05
when I enter that code, it doesn’t do what his balloons do [import]uid: 39628 topic_id: 7510 reply_id: 26654[/import]

his dont move laterally until they hit the ground though or each other. which makes sense for rotating bodies [import]uid: 6645 topic_id: 7510 reply_id: 26657[/import]

wow I didn’t even notice that… thank you haha excuse my noobness. would you have any idea how I would make it do what I mentioned though?
like if I hit the right side, it’d go left, if I hit the bottom, it’d go up (opposites)? [import]uid: 39628 topic_id: 7510 reply_id: 26659[/import]

my guess is work out the distance from the centre of the balloon to the event coordinate and base your impulse values on that

[lua]function moveBall(event)
local vx = (ball.x-event.x)/200
local vy=-0.2
ball:applyLinearImpulse( vx, vy, event.x, event.y )
end[/lua]

it probably isnt very realistic though, but you get the idea [import]uid: 6645 topic_id: 7510 reply_id: 26661[/import]

alright thanks, i’ll play around with it and see what I can do [import]uid: 39628 topic_id: 7510 reply_id: 26663[/import]

Here’s what i did for my game so far. Not very optimized or anything but:

[lua]local function onTouch( event )
if event.phase == “ended” then

local ex, ey = event.x, event.y
local dx,dy,dist
local force = 100
local dir

dx = ex - ballon.x
dy = ey - baloon.y

dist = math.sqrt( dx*dx + dy*dy )

dir = math.atan2(dy,dx)

dx = math.cos( dir ) * force
dy = math.sin( dir ) * force

baloon:applyLinearImpulse( -dx, -dy, ex, ey )
end
end[/lua] [import]uid: 45930 topic_id: 7510 reply_id: 28590[/import]