Hi guys, i wonder how to spawn objects totally random when there are 2-3 different objects coming down altogether?
basically here’s how my script looks like:
[code]–Spawn powerup and bomb
if (level >= 2) then
if(math.random(1,10) == 1) then
powerupspawn()
end
end
if (level == 2) then
if(math.random(1,5) == 1) then
bombspawn()
end
end
– POWERUP SCRIPT
function powerupspawn( objectType, x, y )
powerup = display.newImage(“power-up.jpg”)
powerup.name = “powerup”
powerup.x = math.random(0,330)
powerup.y = -100
powerup.rotation = 10
physics.addBody(powerup, { density=2.0, friction=0.5, bounce=0.3})
localGroup:insert(powerup)
end
– BOMB SCRIPT
function bombspawn( objectType, x, y )
bomb = display.newImage(“ranjau.png”)
bomb.name = “ranjau”
bomb.x = math.random(0,330)
bomb.y = -100
bomb.rotation = 10
physics.addBody(bomb, { density=2.0, friction=0.5, bounce=0.3})
localGroup:insert(bomb)
end
[/code]
with the above script, i wonder why every time the bomb and powerup spawn, they always go side by side? With math.random 0,330 i believe the chance for them to spawn far away one to another should be big but i notice when they spawn together they always spawn very near one to another. Do i need to use another code other than “math.random”?
[import]uid: 114765 topic_id: 21822 reply_id: 321822[/import]

(6 instead of 0 tho…no