Asteroid Field - Spaceshooter

Heeeey everybody! :slight_smile:

As my first “real” JME Java game I want to make a simple space shooter game. I have a first person view (cam), which is movable with WASD…etc. Now the game concept is pretty much like “A Spaceship flying through Asteroids/Obstacles who needs to avoid them”. Now my problem is the asteroid generation. My first thought was to create one every one second and place it randomly between player-100 and player+100 on the x and from player to -100 on the z axis. The problem is that often asteroids are generated in front of others and thats not looking good :stuck_out_tongue: I imagined something like procedural terrain generation. The further the player goes on the z axis, the more asteroids are becoming visible but are randomly placed and removed if they are out of the cameras sight (if you understand what I mean :O). Maybe someone can give me a little bit help or an idea.

Thanks! :slight_smile:

Sorry, but what exactly is your problem?
Your idea seems nice, even if I would advice adding rocks only when one is removed, so that you don’t overfill the area when the player is not moving.
You should also place new rocks in the new field of view of the player. Right/Left if turning, Front/Back if moving Forward/Backward.

My Problem is that if I place a new rock, I don’t know how to handle its random position. Sometimes it’s placed in between rocks that are already on the screen. I want new rocks placed at the end of the rocks that are visible. And with a random value for its position this is a little bit tricky :o

Add rocks only when the player moves, and only in the area that just became near enough to get its share of rocks.
That way, you won’t be adding rocks to areas that already have some.

But how can I “define” that area?

I’d partition space into rectangular blocks, seeding new blocks with asteroids as the player gets near enough (for whatever is “near enough” in your game).

Is the player always flying towards positive z values? I.e. unable to change the viewing angle or flight direction?
Then you could do this:
[java]float lastZ;
protected void update(float fps) {
int currentZ = lastZ + fps * forwardSpeed;
// generate asteroids between lastZ and currentZ ONLY
lastZ = currentZ
Caveat: Make sure that the number of asteroids generated is proportional to fps*forwardSpeed (or by whatever value lastZ gets incremented), else a higher framerate will give you a higher asteroid density.
Caveat 2: I don’t have access to my JME code so details may be wrong.