Jump to content

Random, velocity and center


Recommended Posts

I created two variables: 


X = game.world.randomX; 

Y = game.world.randomY; 


But I would like to create a random Min and Max 

That I have a 600x400 game, I want the objects appear out of the game and go to the middle of the game (also close to downtown, random). With random speed. 

I have also used: 


ball.body.velocity.x = 100 + Math.random () * 200; 


How does the math random?, Sorry too many questions but I have difficulties with English you can not find good guides.




Link to comment
Share on other sites


function creaAsteroide() {




                    // asteroide.body.velocity.x=100+Math.random()*200;

                    // asteroide.body.velocity.y=100+Math.random()*50;



So the asteroid is random in the game, but outside? how can I? I did not understand. Excuse me.

Link to comment
Share on other sites

asteroide.body.velocity.x= this.rnd.integerInRange(minimum number, maximum number);

Its always a random amount with the rnd built in to phaser. So if you wanted the speed of it to be between 200 and 500, you could use integerInRange to decide randomly between the 2 numbers.

So the asteroid could come in at 356 velocity and the next could be 297 speed. It will use any number between the 2 given numbers you specify it to be.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...