hi all,
i need a logic to bounce a box everytime it touches the groud
the bouncing height should be around 100px
below is my code, but when i run it, the bouncing behavior is quite weird… the bouncing is HIGH… LOW… HIGH… LOW… i cant explain. but you can run through the code.
Thanks for your guide
[code]
–[[
Lua 5.1 Copyright © 1994-2006 Lua.org, PUC-Rio
]]
local physics = require(‘physics’)
physics.start()
physics.setGravity( 0, 15 )
local rect = display.newRect(0, 0, 40, 40)
rect:setFillColor(140, 140, 140)
rect.x, rect.y = 100, 100
local ground = display.newRect(0, 0, display.contentWidth, 40)
ground:setFillColor(140, 140, 140)
ground.x, ground.y = 0, 400
physics.addBody(rect, ‘dynamic’, { density=3.0, friction=0.5, bounce=0.0 })
physics.addBody(ground, ‘static’, { density=3.0, friction=0.5, bounce=0.0 })
local function onRectCollision(self, e)
print(‘collide e.phase=’ … e.phase)
if ( e.phase == “began” ) then
self:applyLinearImpulse(0, -100, self.x, self.y)
elseif ( e.phase == “ended” ) then
print(‘collide e.phase=’ … e.phase)
end
end
rect.collision = onRectCollision
rect:addEventListener(‘collision’, rect)
[/code] [import]uid: 10373 topic_id: 8410 reply_id: 308410[/import]