I’m attempting to make my first real physics-based game, and I’m having a bit of trouble.
I have a ball which I am throwing from the lower right of the screen (off the screen). Then, I want it to be thrown in an arc upwards, then come down at the lower left of the screen.
The problem is, the ball is too slow, and the trajectory is way off that I can’t even get it to arc properly… it ends up arcing at the top left of the screen rather than the middle. I’ve tried linearImpulse and also setLinearVelocity and the same problem happens. I’m hard-coding the numbers for the parameters and going by trial-and-error, so I don’t know if this is the right approach and whether I should use a mathematical formula for this.
Here’s my code… hoping someone knowledgeable can help me out with this:
local group = scene.view local pos\_x = g.max\_x()\*1.5 local pos\_y = g.max\_y() ball\_info[id].obj = display.newCircle(pos\_x, pos\_y, ball\_info.radius) physics.addBody(ball\_info[id].obj, "dynamic", {friction = 0, density = 1.3}) group:insert(ball\_info[id].obj) ball\_info[id].obj:setLinearVelocity( -1000, -700 ) --ball\_info[id].obj:applyLinearImpulse( -700, -400, pos\_x, pos\_y )