Add ''physics.addBody'' local imgpath

Hi cloud1/cloud5 are random spawning object dropping down from the top of the screen, i like to add a ‘physics.addBody’ to ‘cloud4’ so it can interact with a ‘Runtime:addEventListener(“collision”, onCollision)’

i can add this code after ‘randomcloud.rotation = math.random(0, 20); – move the cloud’

physics.addBody( randomcloud, "static", { density = .1, bounce = 0.1, friction = .2, radius = 45 } )   

But if i do then all the clouds (1/5) interact with ‘Runtime:addEventListener(“collision”, onCollision)’ .
And if i change 'physics.addBody( randomcloud, ’ to 'physics.addBody( cloud4, ’

physics.addBody( cloud4, "static", { density = .1, bounce = 0.1, friction = .2, radius = 45 } )   

Non of the clouds are showing. how can i make it so only ‘cloud4’ interacts ?
Basecode:

local cloudTable = {} -- Set up cloud table  
function createClouds()  
function initcloud()  
 local cloud1 = {}  
 cloud1.imgpath = "cloud1.png"; --Set Image Path for cloud  
 cloud1.movementSpeed = 10000; --Determines the movement speed of cloud  
 table.insert(cloudTable, cloud1); --Insert cloud into cloudTable  
  
 local cloud2 = {}  
 cloud2.imgpath = "cloud2.png";  
 cloud2.movementSpeed = 12000;  
 table.insert(cloudTable, cloud2);   
  
 local cloud3 = {}  
 cloud3.imgpath = "cloud3.png";  
 cloud3.movementSpeed = 14000;  
 table.insert(cloudTable, cloud3);  
  
 local cloud4 = {}  
 cloud4.imgpath = "badcloud.png";  
 cloud4.movementSpeed = 18000;  
 table.insert(cloudTable, cloud4);   
  
 local cloud5 = {}  
 cloud5.imgpath = "cloud5.png";  
 cloud5.movementSpeed = 21000;  
 table.insert(cloudTable, cloud5);  
   
  
end --END initcloud()   
   
function getRandomcloud()  
local temp = cloudTable[math.random(1, #cloudTable)] -- Get a random cloud from cloudTable  
   
   
local randomcloud = display.newImage(temp.imgpath); --physics.addBody(randomcloud, {isSensor = true});  
randomcloud.myName = "cloud";  
randomcloud.movementSpeed = temp.movementSpeed; -- set the cloud cloudting point  
randomcloud.x = math.random(10, \_W);  
randomcloud.y = -35;  
randomcloud.rotation = math.random(0, 20); -- move the cloud  
cloudMove = transition.to(randomcloud, {  
time = randomcloud.movementSpeed,   
y = 500,  
onComplete = function(self)  
self.parent:remove(self);  
self = nil;  
end   
});  
end  
   
function cloudtGame()  
 cloudTimer1 = timer.performWithDelay(3000,getRandomcloud, 5)  
 cloudTimer2 = timer.performWithDelay(2000,getRandomcloud, 0)  
 cloudTimer3 = timer.performWithDelay(2400,getRandomcloud, 0)   
 cloudTimer4 = timer.performWithDelay(7000,getRandomcloud, 0)   
 cloudTimer5 = timer.performWithDelay(9000,getRandomcloud, 0)   
end--END cloudtGame()  
initcloud()  
cloudtGame()  
end  
  
createClouds()  

Regards Kevin [import]uid: 225288 topic_id: 35835 reply_id: 335835[/import]

Can you share the errorcode?

[import]uid: 181568 topic_id: 35835 reply_id: 142492[/import]

Can you share the errorcode?

[import]uid: 181568 topic_id: 35835 reply_id: 142493[/import]

Hello Kevin,
Can you please post the current code, and a thorough description of what you’re final goal is? The code above is helpful to see, but it seems that you’ve re-sorted or replaced alot of it, and it’s hard to follow what you’re using now. In addition to the current code, a precise description would be helpful… i.e. How are these clouds different? How should they be placed on the screen? What will their behavior be after being placed? etc. etc.

Regards,
Brent [import]uid: 200026 topic_id: 35835 reply_id: 142516[/import]

  • [import]uid: 225288 topic_id: 35835 reply_id: 142500[/import]
  • [import]uid: 225288 topic_id: 35835 reply_id: 142503[/import]

Hi Brent,
I have updated my post.

Regards Kevin. [import]uid: 225288 topic_id: 35835 reply_id: 142522[/import]

Between lines 38 and 39, can you just add something like this?

if ( temp.imgpath == "badcloud.png" ) then physics.addBody( randomcloud, "static", { density=.1, bounce=.1, friction=.2, radius=45 } ) end [import]uid: 200026 topic_id: 35835 reply_id: 142527[/import]

Brent you are my hero!!!

Thank you, this solved my problem. [import]uid: 225288 topic_id: 35835 reply_id: 142530[/import]

Can you share the errorcode?

[import]uid: 181568 topic_id: 35835 reply_id: 142492[/import]

Can you share the errorcode?

[import]uid: 181568 topic_id: 35835 reply_id: 142493[/import]

Hello Kevin,
Can you please post the current code, and a thorough description of what you’re final goal is? The code above is helpful to see, but it seems that you’ve re-sorted or replaced alot of it, and it’s hard to follow what you’re using now. In addition to the current code, a precise description would be helpful… i.e. How are these clouds different? How should they be placed on the screen? What will their behavior be after being placed? etc. etc.

Regards,
Brent [import]uid: 200026 topic_id: 35835 reply_id: 142516[/import]

  • [import]uid: 225288 topic_id: 35835 reply_id: 142500[/import]
  • [import]uid: 225288 topic_id: 35835 reply_id: 142503[/import]

Hi Brent,
I have updated my post.

Regards Kevin. [import]uid: 225288 topic_id: 35835 reply_id: 142522[/import]

Between lines 38 and 39, can you just add something like this?

if ( temp.imgpath == "badcloud.png" ) then physics.addBody( randomcloud, "static", { density=.1, bounce=.1, friction=.2, radius=45 } ) end [import]uid: 200026 topic_id: 35835 reply_id: 142527[/import]

Brent you are my hero!!!

Thank you, this solved my problem. [import]uid: 225288 topic_id: 35835 reply_id: 142530[/import]