@Nick & @Chinmay!!
I was JUST at the point where you guys were at. Thanks for all the help so far.
Now like Chinmay mentioned however, we have an issue with the further away an object is from our tap event, the GREATER the force that is applied to it.
My question is now, how do we apply an inversely proportional amount of force the further away we are from the explosion origin? I’ve tried dividing the force, multiplying it…but I’m missing something like the inverse of the distance and then dividing that against the force on the axes?
Here’s the sample code with primitives and no graphics so anyone can jump in.
Also, I’ve become convinced that ‘friction’ does not a damned thing, and the only way you can get the objects to behave properly is to apply linear damping. 
Here we go:
[code]
physics = require “physics”
physics.start()
physics.setDrawMode( “hybrid” )
physics.setGravity( 0, 0 )
furniture = {}
gameBoard = display.newGroup()
background = display.newRect(0,0,1024,1024)
background:setFillColor(0,175,50)
background:setReferencePoint(display.TopLeftReferencePoint)
background.x = 0
background.y = 0
function getDistanceTo( sourceX, sourceY, x, y )
– Returns distance (in pixels) from object’s location to given coordinates.
local theDistance = math.ceil(math.sqrt( ((y - sourceY) * (y - sourceY)) + ((x - sourceX) * (x - sourceX)) ))
return theDistance
end
function handleTouch(event) – still actually local
print(“touch:”…event.phase)
if “ended” == event.phase then
– Set an effect range that will check against
– all other pieces of furniture. If the furniture’s
– x and y location are within this range, then affect
– them with our 'splosion!
local range = 200
for i=1,#furniture do
local tempDistance = getDistanceTo(event.x,event.y,furniture[i].x,furniture[i].y)
if(tempDistance local tempX
local tempY
tempX = event.x - furniture[i].x
tempY = event.y - furniture[i].y
– Vary ‘force’ if you want to increase or decrease
– the force at which the pieces of furniture go flying
– local force = 1
local force = 1
– We put a negative sign in front of our tempX and tempY
– so the objects move AWAY from the event.x and y…
– If for some reason you wanted to ‘suck’ the objects
– TOWARDS the event.x and y, you’d take the negative sign
– off.
– Away…
furniture[i]:applyLinearImpulse( -tempXforce,-tempYforce,furniture[i].x,furniture[i].y)
– Towards…
--furniture[i]:applyLinearImpulse( tempXforce,tempYforce,furniture[i].x,furniture[i].y)
end
end
end
end
– Add the background event handler to our background
– displayRect…
background:addEventListener ( “touch”, handleTouch )
chairMaterial = { density = 1.0, bounce = 0.5 }
tableMaterial = { density = 1.0, bounce = 0.1 }
for i=1,10 do
furniture[i] = {}
local tempNumber = math.random(1,3)
tempSize = 64
local tempValue = math.random(1,2)
if(tempValue==1)then
– Make a table!
furniture[i] = display.newCircle(0,0,30,30)
furniture[i]:setFillColor(255,255,0)
physics.addBody( furniture[i], tableMaterial )
furniture[i].linearDamping = 10
furniture[i].angularDamping = 2
else
– Make a chair!
furniture[i] = display.newRect(0,0,30,30)
furniture[i]:setFillColor(175,50,110)
physics.addBody( furniture[i], chairMaterial )
furniture[i].linearDamping = 1
furniture[i].angularDamping = 2
end
furniture[i].x = math.random(200,250)
furniture[i].y = math.random(200,250)
furniture[i].linearDamping = 4
furniture[i].angularDamping = 2
furniture[i].name=“furniture”…i
end
[/code]
The chairs are the squares and they’re lighter and more likely to move fast, whereas the tables I’ve increased the damping on them. We’re so close, I’m DYIN over here!!
Thanks for the help and effort! [import]uid: 11636 topic_id: 12005 reply_id: 43970[/import]