Another Monday after a weekend off. Gotta motivate myself to put in the work. I'm going to start with the space junk spawner. I'm tired of having to push a button when I want new junk. And I hate that it always spawns in the same place. There are a number of ways I can do this. What I want to do is spawn the space junk off-screen, directly in front of the player's ship. This is a complicated thing to do, so maybe instead I'll do something simple for now.
Let's start with spawning in a random location on-screen! For that, I need to know the world boundary of the camera viewport. ViewportToWorldPoint should do the trick! So, I'm having trouble making it happen properly. I need to think it through a bit more. Okay, I think I have it figured out now. I get the bottom left and top right points (gives me a min and max on both X and Y for the camera viewport bounds). I feed the Xs and the Ys into their own respective random function, then feed those into a simple Vector2 as the spawn position of the space junk!
Well, my first mistake was using "Camera Get Current" instead of "Camera Get Main". Once I fixed that, it's working perfectly! I don't really want space junk to spawn on the player's screen though. I would prefer it to spawn off screen, but I also don't want to just randomly spawn the stuff off-screen. I think for now, this works. But I must make some sort of check. . .
Okay, so now I can control the maximum number of space junk and automatically spawn in more as needed. The problem is, it's too fast. As soon as I blast one space junk, another pops up. A wait statement just doesn't work. I tried putting in a random wait for 5-10 seconds, but because of the wait, for the first 5-10 seconds there's no space junk, so every frame it's trying to make more . . . That's bad.
You know what? For now, spawning a new piece of space junk instantly after one gets destroyed is fine. I'm not trying to make the perfect game yet, I'm just trying to make a game. This works for now, I can modify it later if I want.
Next step is to work on pickups and loot. . . well, at least pickups. I also need to add the moving background, and have the camera follow the player.
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.