I have this code below, where an image is bouncing around 4 walls.
But I don't want my image to rotate at all, but I would like to have my image bounce in X+Y direction when it hits a wall. Atm it bounces in X+Y the first time and then it's only X or Y direction. Anyone else with this problem?
I tried setting the cueball in SimplePool to isFixedRotation = true and the same thing happens there, the first bounce at a wall is correct and then it's bouncing only in X or Y direction depending on which wall it hits.
Can anyone help me? How can I get an image to bounce around with physics but without rotation of the image?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | local physics = require("physics") physics.start() physics.setDrawMode( "hybrid" ) local top = display.newRect(10,-50,_W,10) physics.addBody(top, "static", { friction=3.5, bounce=0.5, filter=wallCollisionFilter}) top.name = "top" local left = display.newRect(-50,-50,10, _H+100) physics.addBody(left, "static", { friction=3.5, bounce=0.5, filter=wallCollisionFilter}) left.name = "left" local bottom = display.newRect(0,_H+50,_W, 10) physics.addBody(bottom, "static", { friction=3.5, bounce=0.5, filter=wallCollisionFilter}) bottom.name = "bottom" local right = display.newRect(_W+50,-50, 10, _H+100) physics.addBody(right, "static", { friction=3.5, bounce=0.5, filter=wallCollisionFilter}) right.name = "right" local image11_org = display.newImageRect( "assets/image11_org.png", 73, 47 ) local image11_gro = display.newGroup() image11_gro:insert(image11_org) image11_gro.x = 185 image11_gro.y = 252 physics.addBody( image11_gro, { density=0.2, friction=0.2, bounce=0.5, radius=30, filter=imageCollisionFilter } ) image11_gro:applyLinearImpulse(60,-50, image11_gro.x, image11_gro.y) image11_gro.linearDamping = 0.3 image11_gro.angularDamping = 2 image11_gro.isFixedRotation = true |
If I remove the friction on the wall it seems to work as it should.