Hello,
Easy problem short, how do I disable a bounce?
I have made this but it complains that the line "self.box1.bodyType = “static” " is wrong and I haven’t found an answer after a long research. My idea was that I change the falling objects bodytype to static when the collision happens so that it would not bounce. Hopefully I will get an answer!
local physics = require “physics”
physics.start()
local box1 = display.newImage( “hugeBox1.png” )
physics.addBody( box1, “dynamic”, { density = 1.0, friction = 0.3,
bounce = 0.2 } )
box1.myName = “Box 1”
local box2 = display.newImage( “hugeBox2.png”, 0, 350)
physics.addBody( box2, “static”, { density = 1.0, friction = 0.3,
bounce = 0.2 } )
box2.myName = “Box 2”
local function onCollision( self, event )
if event.phase == “began” and self.myName == “Box 1” then
self.box1.bodyType = “static”
end
end
box1.collision = onCollision
box1:addEventListener( “collision”, box1 )
box2.collision = onCollision
box2:addEventListener( “collision”, box2 )
Edit: of course after spending 5 hours to get the answer, I found it right away after posting this topic…
If somebody is having the same problem as I am, the code needed is:
event.contact.bounce = false
and the bounce is “literally” enabled.