I am new to Corona, Lua and Box2D, so perhaps I am missing something obvious here. I am exploring development for a game where a ball should bounce off/ roll on “walls” with different inclinations. As you can see from the example below, if I define my “wall” from “right to left” the ball, which is falling from the top, will bounce over it. If I define my downward-sloping “wall” from “left to right” the ball, which is falling from the top, will stick to it. Besides wanting to solve the bug, I would also like to understand why that is happening. Has anyone encountered this problem?
PS: setting velocity threshold to 0 will not solve this.
[code]
– Starts and configures physics
physics = require (“physics”)
physics.start(true)
physics.setGravity(0, 20)
physics.setDrawMode( “hybrid” )
– physics.setDrawMode( “debug” )
physics.setPositionIterations( 16 )
physics.setVelocityIterations( 6 )
physics.setMKS( “velocityThreshold”, 10)
– Draw ball
local ball = display.newCircle( 0, 0, 30)
ball:setFillColor(0, 255, 0)
ball.x = display.contentHeight
ball.y = display.contentWidth/100
– Creates physic “overlay” for ball
physics.addBody(ball, {density=100, bounce=0, radius = 30, friction=0.0})
– Set coordinates “upwards” => this is fine
–x0 = ball.x+200
–y0 = ball.y+200
–x1 = ball.x-200
–y1 = ball.y+400
– Set coordinates “downwards” => this is causing a “sticky line”
x0 = ball.x-200
y0 = ball.y+200
x1 = ball.x+200
y1 = ball.y+400
– Draw line
local segment = {}
segment = display.newLine(x0, y0, x1, y1)
segment.width = 15
– Creates physic “overlay” for line
Width = (x1 - x0)
Height = (y1 - y0)
rectangle = {Width,Height,0,0,0,3,Width,Height+3}
physics.addBody(segment, “static”, { bounce = .8, density=100, friction=0.01, shape = rectangle})
[/code] [import]uid: 159908 topic_id: 28390 reply_id: 328390[/import]