Creating an explosion blast

I’m to make an object explode on a collision.

The collsion works, I’m getting my explosion and sound, but no applyForce is occurring.

Thanks

[code]
local function onbarrelCollision ( self, event )

if ( event.force > 4 ) then

local forcex = event.other.x -self.x
local forcey = event.other.y -self.y - 20
print("event.other.x- "…event.other.x)
print("event.other.y- "…event.other.y)
print("forcex- "…forcex)
print("forcey- "…forcey)

event.other:applyForce( forcex, forcey, event.other.x, event.other.y )

explosionPoof.x = event.target.x
explosionPoof.y = event.target.y
explosionPoof.alpha = 0
explosionPoof.isVisible = true

if explosionpoofTween then transition.cancel( explosionpoofTween ); end

local explosionfadePoof = function()
transition.to( explosionPoof, { time=300, alpha=0 } )
end
explosionpoofTween = transition.to( explosionPoof, { time=100, alpha=1.0, onComplete=explosionfadePoof } )
if audioset == 1 then
audio.play( explosionSound )
end

self:removeSelf()
self = nil

end
end

– Set table listeners in each board to check for collisions
barrelwood.postCollision = onbarrelCollision
barrelwood:addEventListener( “postCollision”, barrelwood )
[/code] [import]uid: 78446 topic_id: 16534 reply_id: 316534[/import]

If you want this to get looked at in great detail you really need to provide some plug and play code - or a downloadable zip.

People are more likely to help that way :slight_smile:

Peach [import]uid: 52491 topic_id: 16534 reply_id: 61935[/import]

The link does not work: http://dl.dropbox.com/u/41194248/explosion.zip [import]uid: 14218 topic_id: 16534 reply_id: 63434[/import]

Oh, Ok, I just figured it was something simple.

Here is a demo zip
http://dl.dropbox.com/u/41194248/explosion.zip

Thanks

Dan [import]uid: 78446 topic_id: 16534 reply_id: 61994[/import]

It’s ready, my computer was off, had a power outage today.

Dan [import]uid: 78446 topic_id: 16534 reply_id: 63477[/import]

In the mean time I cheated, I have a circle appear that moves the stuff like a blast, but I don’t get a fall off effect.

Dan [import]uid: 78446 topic_id: 16534 reply_id: 63478[/import]

This seems to work better than the circle expanding at least.

I commented out your method, just in case.
[blockcode]
local function onbarrelCollision ( self, event )

if ( event.force > 4 ) then

forcex=(event.other.x - self.x) / 2
forcey=(event.other.y - self.y - 20)/2

explosionPoof.x = event.target.x
explosionPoof.y = event.target.y
explosionPoof.alpha = 0
explosionPoof.isVisible = true

if explosionpoofTween then transition.cancel( explosionpoofTween ); end

local explosionfadePoof = function()
transition.to( explosionPoof, { time=300, alpha=0 } )
end
explosionpoofTween = transition.to( explosionPoof, { time=100, alpha=1.0, onComplete=explosionfadePoof } )

audio.play( explosionSound )

event.other:applyLinearImpulse(forcex, forcey, event.other.x, event.other.y)

self:removeSelf()
self = nil

–[[local function forceSensorE( event )
fsensorRadius = 200
forceSensor = display.newCircle( 30,30, fsensorRadius )
game:insert( forceSensor )
forceSensor.isVisible = false
forceSensor.x = forcex
forceSensor.y = forcey
forceSensor.isSensor = true
physics.addBody(forceSensor, “static”)
local forceExpand = function()
forceSensor:removeSelf()
end
forceExpandTween = transition.to( forceSensor, { time=10, onComplete=forceExpand } )

end
timer.performWithDelay( 100, forceSensorE)]]–
end
end[/blockcode] [import]uid: 89724 topic_id: 16534 reply_id: 63495[/import]

Thanks x2495iiii that got me in the right direction, your way worked, but only effected the dropped ball, but didn’t effect the other barrels, there was no blast area, but I got it to work with a blast area-

local function onbarrelCollision ( self, event )  
   
 if ( event.force \> 4 ) then  
   
 forcex=(event.other.x - self.x) / 2  
 forcey=(event.other.y - self.y - 20)/2  
   
 explosionPoof.x = event.target.x  
 explosionPoof.y = event.target.y  
 explosionPoof.alpha = 0  
 explosionPoof.isVisible = true   
   
 if explosionpoofTween then transition.cancel( explosionpoofTween ); end  
   
 local explosionfadePoof = function()  
 transition.to( explosionPoof, { time=300, alpha=0 } )   
 end  
 explosionpoofTween = transition.to( explosionPoof, { time=100, alpha=1.0, onComplete=explosionfadePoof } )  
   
 audio.play( explosionSound )  
  
 self:removeSelf()   
 self = nil  
  
 fsensorRadius = 100  
 local forceSensor = display.newCircle( 30,30, fsensorRadius )  
 game:insert( forceSensor )   
 forceSensor.isVisible = false  
 forceSensor.isSensor = true  
 forceSensor.x = event.target.x  
 forceSensor.y = event.target.y  
  
 local function forceSensorE( event )   
  
 physics.addBody(forceSensor, "static")  
 forceSensor:applyLinearImpulse(forcex, forcey, forceSensor.x, forceSensor.y)  
  
 local forceExpand = function()  
 forceSensor:removeSelf()  
 end  
  
 forceExpandTween = transition.to( forceSensor, { time=500, onComplete=forceExpand } )  
   
 end   
 timer.performWithDelay( 100, forceSensorE)   
  
 end  
  

Dan [import]uid: 78446 topic_id: 16534 reply_id: 63930[/import]

Your original code only affected the object that hit the barrel (event.other), so that’s what I went for. It’s possible, though a little more difficult, to create a blast radius using linear impulses and a function that tests to see what objects are nearby. [import]uid: 89724 topic_id: 16534 reply_id: 63936[/import]