Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Pickups Spawn Pickups Randomly

Liu Cheng
Liu Cheng
22,359 Points

Some flies are on the rock that cannot be collected.

The spawn works well for me. However, some flies appear on the rock and I cannot collected, as I collect more flies on the ground, fewer flies I can actually collect.

3 Answers

Try reducing the spawn area. It's straightforward enough for the example of this simple game. If you were wanting it to be more sophisticated you'd add in checks where it was being spawned and if it's over the rocks or not (and to not spawn if so). Probably using ray casting but that's out of the scope for this course and so easiest thing is to reduce the area to be inside the rocks.

Tommy Choe
Tommy Choe
38,156 Points

I also had a problem with flies spawning on the rocks but simply changing the spawn area wasn't doing it for me. I eventually found out that I had changed the x and y coordinates of my terrain for some reason. Once I reset those values, the flies were spawning normally even without reducing the spawn area.

how do you fix it