How to disable X gravity?

Hello,
 
I made a game where a ball object is dropping down and thin rectangles are spawning to block the way, which are coming from the bottom to the top of the screen. The problem is that when the ball hits the corner of rectangles, it gets a bit of X gravity, which makes the ball object hard to handle.
 
I have physics set to:

local physics = require “physics”
physics.start()
physics.setGravity (0, 5)

The ball is:

physics.addBody(ball, “dynamic”, {density = 1, friction = 0, bounce = 0.2})

And the rectangles are:

physics.addBody(plank1, “static”, {density = 1, friction = 0, bounce = 0.2})

physics.addBody(plank2, “static”, {density = 1, friction = 0, bounce = 0.2})

If somebody knew some kind of a clue what could be the answer to my problem, it would be appreciated!

You could create a runtime listener where you constantly set the x velocity to 0. It would look something like this:

[lua]

local function enterFrameFunction()

     local vx, vy = ball:getLinearVelocity() --get the current linear velocity so we can make the x 0 but not change the y

     ball:setLinearVelocity(0, vy) – set the x velocity to 0 but keep the y velocity what it was

end

Runtime:addEventListener(“enterFrame”, enterFrameFunction)

[/lua]

Thanks for the quick response!

I never thought like that and it worked well. Once again, thanks!

You could create a runtime listener where you constantly set the x velocity to 0. It would look something like this:

[lua]

local function enterFrameFunction()

     local vx, vy = ball:getLinearVelocity() --get the current linear velocity so we can make the x 0 but not change the y

     ball:setLinearVelocity(0, vy) – set the x velocity to 0 but keep the y velocity what it was

end

Runtime:addEventListener(“enterFrame”, enterFrameFunction)

[/lua]

Thanks for the quick response!

I never thought like that and it worked well. Once again, thanks!