Random Angle in Cone

Hello. I would like to add a random force to an object to make it fly at a random angle, but only within a cone to limit where it gets to fly. I’ve gotten the random angle part down, but I don’t know how to do the cone. The cone will be pointed straight upwards. Is it possible to make an object only spawn at a random angle within a cone, or is the engine too underpowered to handle this? Thanks in advance.

there is a randominrange(x,y) I’m not sure if this is what you are looking for

I would use a ghost pixel as tip of the cone, then Create the object and Put the object around the cone tip, at the desired distance and angle.

How do I use randominrange?

Is the ghost pixel a new object that has to be pinned to the player? Will the angle be random?

Place the pixel at the tip of your cone, I don’t know if you need to pin it to your player, depends on your game.
The angle will be random if you make it so, using the Random() function. If you want a random angle between 70° and 110°, you do 70+Random(40).

I only wanted to spawn an object that launches at a random angle.
However, your suggestion of “Number+Random(Number)” seems to be working! I’m surprised that it was that simple! Now I can make shotguns if I want to!
Thank you mate. You saved me a lot of time.
Hey, maybe you should make a cone example for the next update! :wink:

1 Like