Problem with applyForce

I’m having a problem applying a force to an object - in the code below I would think that by applying a force along the y axis would make the object travel straight along the y axis but this doesn’t seem to be the case. If I run the code, the object goes down and to the right instead of straight up. What am I missing here?

[code]
– myBody Game
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
physics.setDrawMode( “hybrid” )

function main()

– Create groups to hold assets
background = display.newGroup()

– Load background image
local bgImage = display.newImage(“background.png”)
background:insert( bgImage, true ); bgImage.x = 160; bgImage.y = 240

– Initialize myBody
myBody = display.newImage(“ball.png”)
myBody.x = 160; myBody.y = 240
physics.addBody( myBody, { density = 1.0, friction = 0.3, bounce = 0.2 })

– Listen for touch
local touchListener = function(event)
if event.phase == “ended” then
myBody:applyForce( myBody.x, myBody.y + 100, myBody.x, myBody.y )
else
–do nothing
end
return true
end

background:addEventListener(“touch”, touchListener )
end

main()
[/code] [import]uid: 3018 topic_id: 2142 reply_id: 302142[/import]

simplified the code, shouldn’t myBody:applyForce( myBody.x, myBody.y + 100, myBody.x, myBody.y ) make the body go straight up?

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )

myBody = display.newImage(“ball.png”)
myBody.x = 160; myBody.y = 240

physics.addBody( myBody, { density = 1.0, friction = 0.3, bounce = 0.2 })
myBody:applyForce( myBody.x, myBody.y + 100, myBody.x, myBody.y )

[code] [import]uid: 3018 topic_id: 2142 reply_id: 6378[/import]

Try:

myBody:applyForce( 0, 100, myBody.x, myBody.y )

The first two parameters specify the force’s direction - your example gives it an x-coordinate value which is not what you want.

Note that the force will only be applied for a single frame duration…
see “http://developer.anscamobile.com/issues/1957

-Frank.
[import]uid: 8093 topic_id: 2142 reply_id: 6381[/import]

Thanks, that does the trick [import]uid: 3018 topic_id: 2142 reply_id: 6393[/import]