Hi all,
I’m a little puzzled here… I have a very simple game stage which is just four rectangles forming a box. Inside this box a ball is moving around, bouncing off the walls. The stage is set with zero gravity and there is no friction on any of physical bodies, so the ball just keeps bouncing around forever. So far so good.
Then I add an obstacle (another rectangle) in the middle of the stage. Now the ball starts acting up really weird. At random impacts with either the box walls or the obstacle, the ball will slow down and crawl to the next wall (or obstacle), where it may or may not pick up speed again on impact. Can anyone explain why this is happening?
The code is posted below. If you comment out the four lines that add the obstacle to the stage, the ball runs smoothly. Comment the lines back in and the ball starts acting up.
-- code demonstrating weird behaviour :-)
local screenW, screenH = display.contentWidth, display.contentHeight
local physics = require("physics")
physics.start()
physics.setGravity( 0, 0.0 )
physics.setDrawMode( "normal" )
--physics.setDrawMode( "debug" )
--physics.setDrawMode( "hybrid" )
-- draw top and bottom borders
local topBorder = display.newRect(0, 0, screenW, 10)
topBorder.x = screenW / 2; topBorder.y = 0;
physics.addBody( topBorder, "static", { density=0.0, friction=0.0, bounce=0.0 } )
local bottomBorder = display.newRect(0, 0, screenW, 10)
bottomBorder.x = screenW / 2; bottomBorder.y = screenH;
physics.addBody( bottomBorder, "static", { density=0.0, friction=0.0, bounce=0.0 } )
-- draw left and right borders
local leftBorder = display.newRect(0, 0, 10, screenH)
leftBorder.x = 0; leftBorder.y = screenH / 2
physics.addBody( leftBorder, "static", { density=0.0, friction=0.0, bounce=0.0 } )
local rightBorder = display.newRect(0, 0, 10, screenH)
rightBorder.x = screenW; rightBorder.y = screenH / 2
physics.addBody( rightBorder, "static", { density=0.0, friction=0.0, bounce=0.0 } )
-- draw obstacle
local obstacle = display.newRect(0, 0, 10, screenH / 2)
obstacle.x = screenW / 2
obstacle.y = screenH / 2
physics.addBody( obstacle, "static", { density=0.0, friction=0.0, bounce=0.0 } )
-- draw ball
local ball = display.newCircle(0, 0, 10)
ball.x = 20; ball.y = 20
physics.addBody( ball, "dynamic", { density=0.0, friction=0.0, bounce=1.0 } )
-- start ball movement
ball:setLinearVelocity( 300, 300 )
I’m using simulator version 2011.704 on Windows.
Help would really be appreciated
[import]uid: 118371 topic_id: 20553 reply_id: 320553[/import]
