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]