I have a rectangle that’s suppose to stop a ball from going down to the bottom of the screen . But soetimes the ball goes straight through the rectangle and I don’t know why or how to fix it .
local myRectangle = display.newRect( 100, 100, 50, 20 ) myRectangle:setFillColor( 0.5, 0.2, 0.2 ) physics.addBody(myRectangle, "static", {friction = 2, density=5}) -- touch listener function function myRectangle:touch( event ) if event.phase == "began" then display.currentStage:setFocus( self, event.id ) self.isFocus = true self.x0 = self.x self.y0 = self.y elseif( self.isFocus ) then local dx = event.x - event.xStart local dy = event.y - event.yStart self.x = self.x0 + dx self.y = self.y0 + dy if event.phase == "ended" then display.currentStage:setFocus( self, nil ) self.isFocus = false end end return true end
-- create image of a ball Ball = display.newCircle(100, 20, 10) physics.addBody(Ball, "dynamic", {bounce = 0.1, density=.1}) Ball:setFillColor( 1.5, 0.2, 0.2 ) Ball:setStrokeColor( 0, 0, 5 ) Ball:applyLinearImpulse( .1, .00, 0, 0)