I’ve just whipped up a quick example of a “blocks” environment. Similar to the types of alphabet blocks that children would play with. I’ve tried to create a realistic environment where the canvas height is about equal to 1 meter. And the blocks are maybe 4-6 inches in height/width. It seems to work ok although when dragging and stacking they feel very “rubbery”.
If you stack them on top of one another and then click and drag down they bounce like rubber balls almost, even though their bounce parameters are set to 0.0.
I would greatly appreciate any assistance in helping me to make these less bouncy. Thank you!!!
[lua]–> ---------------------------------------------
–> Setup Display
–> ---------------------------------------------
display.setStatusBar (display.HiddenStatusBar)
–system.activate (“multitouch”)
–> ---------------------------------------------
–> ---------------------------------------------
–> Start Physics
–> ---------------------------------------------
local physics = require (“physics”)
physics.start (true)
physics.setGravity (0, 20)
physics.setScale (200)
–physics.setDrawMode (“hybrid”)
–> ---------------------------------------------
–> ---------------------------------------------
–> Enable Physics based dragging
–> ---------------------------------------------
local gameUI = require (“gameUI”)
local function dragBody (event)
–[[
gameUI.dragBody (event, {
maxForce = 20000,
frequency = 1000,
dampingRatio = 1.0
})
]]
gameUI.dragBody (event)
end
–> ---------------------------------------------
–> ---------------------------------------------
–> Create Floor
–> ---------------------------------------------
local floor = display.newRect (0, display.contentHeight, display.contentWidth, 1)
physics.addBody (floor, “static”, {
bounce = 0.1,
friction = 10.0
})
–> ---------------------------------------------
–> ---------------------------------------------
–> Create Environment Group
–> ---------------------------------------------
local environment = display.newGroup ()
–> ---------------------------------------------
–> ---------------------------------------------
–> Create block function
–> ---------------------------------------------
function newBlock ()
–> Generate random number between 20 - 60
local randWidth = math.random (40) + 20
local randHeight = math.random (40) + 20
–> Generate random x value
local randX = math.random (display.contentWidth)
local blockMaterial = {
density = 1.0,
friction = 10.0,
bounce = 0.0
}
local block = display.newRect (0, 0, randWidth, randHeight)
block.x = randX
block.y = -100
block.strokeWidth = 1
block:setStrokeColor (255, 255, 255, 255)
block:setFillColor (255, 255, 255, 128)
physics.addBody (block, blockMaterial)
block.isFixedRotation = true
–block.isBullet = true
–block.angularDamping = 20
block:addEventListener (“touch”, dragBody)
end
–> ---------------------------------------------
–> ---------------------------------------------
–> Create our blocks
–> ---------------------------------------------
local dropBlocks = timer.performWithDelay (100, newBlock, 10)
–> ---------------------------------------------[/lua] [import]uid: 10747 topic_id: 3419 reply_id: 303419[/import]
[import]uid: 10747 topic_id: 3419 reply_id: 10303[/import]