I’m trying to create 4 walls with a ball that bounces around inside the walls. When I use the code below, the ball passes through a wall instead of a third bounce. I thought maybe the walls were sleeping but even with physics.start(true) the ball falls through.
I hope I am doing something wrong.
[code]
local windowWidth = display.contentWidth
local windowHeight = display.contentHeight
local physics = require “physics”
physics.start()
physics.setScale(30)
physics.setGravity(0, 0)
physics.setDrawMode(“normal”) – debug, hybrid
local wallProperties = { friction = 0.0, bounce = 0.5}
local leftWall = display.newLine(50,0,50,windowHeight)
leftWall:setColor(0,255,0)
leftWall.width = 20
physics.addBody(leftWall, “static”, wallProperties)
local rightWall = display.newLine(windowWidth-50,0,windowWidth-50,windowHeight)
rightWall:setColor(0,255,0)
rightWall.width = 20
physics.addBody(rightWall, “static”, wallProperties)
local upWall = display.newLine(0,0,windowWidth,0)
upWall:setColor(0,255,0)
upWall.width = 20
physics.addBody(upWall, “static”, wallProperties)
local downWall = display.newLine(0,windowHeight,windowWidth,windowHeight)
downWall:setColor(0,255,0)
downWall.width = 20
physics.addBody(downWall, “static”, wallProperties)
local ballShape = {-5, -5, 5, -5, 5, 5, -5, 5}
local ball = display.newImage(“ball.png”)
ball.x = 160
ball.y = 350
physics.addBody(ball, { density = 3.0, friction = 0.0, bounce = 0.3, shape = ballShape})
ball:applyForce(-100,100,ball.x,ball.y)
[/code] [import]uid: 9562 topic_id: 3074 reply_id: 303074[/import]
Use rectangles instead–for example, swap the the following lines in your code: