How to spawn randomly falling objects 80% times where my ball is there

hey

enemy spawns randomly on the xcordinate…then it falls from above…i want it to spawn where my ball is there 80% times…

virus[enemyCounter].x = math.random(screenLeft,screenRight)

this code randomly decides the position of enemy

and my ball is draggable…those enemy should randomly place 80 % times where my position of ball is there

I’m not sure what you mean. English is not my native language. Could you describe what you want simpler or diff?

May be this link will be helpful http://lua-users.org/wiki/MathLibraryTutorial

EDIT : 

math.randomseed( os.time() ) local rand =&nbsp;math.random local i = rand(1, 10) if ( i \<= 8 ) then &nbsp; &nbsp;... else &nbsp; ... end

i want my enemy to spawn most of the time at x position of my ball…suppose my ball is 250 in x cordinate, then 80% the enemy should spawn in 250 of the x cordinate

English is not my native language too 

What is your native language? We do have specific forums for several languages. if you both speak the same native language, and we have a forum for that, you could post your questions and answers there.

Rob

What do you think about code below?

-- top of file&nbsp; math.randomseed( os.time() ) ... local function spawnEnemies() &nbsp; local rand =&nbsp;math.random &nbsp; local i = rand(1, 10) &nbsp; &nbsp; &nbsp;... &nbsp; if ( i \<= 8 ) then &nbsp; &nbsp; enemy.x = ball.x &nbsp; &nbsp; ... &nbsp; else &nbsp; &nbsp;&nbsp;enemy.x = someWhereElseThatBall(&nbsp;ball.x&nbsp;) &nbsp; &nbsp; &nbsp;... &nbsp; end end

Edit : My native language is polish :slight_smile:

I’m not sure what you mean. English is not my native language. Could you describe what you want simpler or diff?

May be this link will be helpful http://lua-users.org/wiki/MathLibraryTutorial

EDIT : 

math.randomseed( os.time() ) local rand =&nbsp;math.random local i = rand(1, 10) if ( i \<= 8 ) then &nbsp; &nbsp;... else &nbsp; ... end

i want my enemy to spawn most of the time at x position of my ball…suppose my ball is 250 in x cordinate, then 80% the enemy should spawn in 250 of the x cordinate

English is not my native language too 

What is your native language? We do have specific forums for several languages. if you both speak the same native language, and we have a forum for that, you could post your questions and answers there.

Rob

What do you think about code below?

-- top of file&nbsp; math.randomseed( os.time() ) ... local function spawnEnemies() &nbsp; local rand =&nbsp;math.random &nbsp; local i = rand(1, 10) &nbsp; &nbsp; &nbsp;... &nbsp; if ( i \<= 8 ) then &nbsp; &nbsp; enemy.x = ball.x &nbsp; &nbsp; ... &nbsp; else &nbsp; &nbsp;&nbsp;enemy.x = someWhereElseThatBall(&nbsp;ball.x&nbsp;) &nbsp; &nbsp; &nbsp;... &nbsp; end end

Edit : My native language is polish :slight_smile: