- Home /
Emitting objects at a progressive rate randomly in a 2D game
I am planning on developing a small 2D Android and iPhone game and I need to go over a few things before I can start building.
I was wondering how to build a script in Javascript to emit a prefab within a ring-like parameter in a 2D style game. I will try to explain with images.
In this image, The green square represents the Camera's view, and the red ring of sorts represents the parameters of which I want the enemies (those blob things) to spawn.
I need help developing a script that randomly generates a position within the parameter and places an object of choice there (to be changed in the inspector tab). I also need to have the spawn rate changeable through time, as in it spawns faster over a period of time.
If anyone can help me, it would be so great. I'm willing to go into further detail, so just ask if you need that.
Thanks.
Answer by Benproductions1 · May 20, 2013 at 04:14 AM
How about using 2 random numbers one for magnitude, which would be between the 2 radii and one for direction (angle) which would be between 0 and 2pi. Then you can use sin/cos to get the x and y values. Then cast that to a vector and pass it into the Instantiate
function you are already calling :)
Thanks heaps, I just didn't really know where to begin to randomise each position, but I got it working.
Thanks
Your answer
Follow this Question
Related Questions
Emmiter in time intervals 1 Answer
(Android) Timer change script help 0 Answers
Problem Min and Max Time 1 Answer
fuel compsumation 0 Answers
Force mode and delta timing 1 Answer