Random Moving Objects

A

Alexis3335

Guest
Hello,
I am making an Asteroid-like game and I am a begginer.I now have a spaceship that follows your cursor and moves and it even has a little flame animation,but I have trouble with the "asteroids".I made the object with the sprite,but how can I make it so it moves randomly on the room and when it hits the player,you go to the "Game Over" room I will make (for this part of coding,I'm okay)Could you guys help me?Thanks for your time :)
(Picture is showing my Spaceship object coding for now,idk if it's usefull but I put it just in case)View attachment 18590
 
J

Jdown79

Guest
so in create you can call image_angle to be random on spawn ( I think irandom(0,359))
and then call direction to that angle, and apply a speed.

as for game over, if place_meeting() is how you can call the collision.
 
A

Alexis3335

Guest
so in create you can call image_angle to be random on spawn ( I think irandom(0,359))
and then call direction to that angle, and apply a speed.

as for game over, if place_meeting() is how you can call the collision.
I don't really get,I wrote irandom(0,359) but you only need 1 argument,not 2.As for the speed and direction,what commands should I use?
 

flerpyderp

Member
I don't really get,I wrote irandom(0,359) but you only need 1 argument,not 2.
irandom indeed requires only 1 argument, Jdown79 likely meant irandom_range which isn't necessary if the lowest value required is 0.

As for the speed and direction,what commands should I use?
You could use the functions random_range, irandom_range, or choose in the create event of those objects. I recommend reading the manual on how these commonly used functions work.
 
J

Jdown79

Guest
Ahh yes, my mistake, i did mean random_range, but as flerpy has said, is an unnecessary function for this case.
 
A

Alexis3335

Guest
I found a fix on YouTube,but thanks for your help! I will read the manual too :)
 
Top