Spawning Random Objects

Playing around with spawning random objects to go with my new scrolling background technique. I have a collection of different objects the player is going to have to jump over while they try to escape from the zombies. As you can see I have each object randomly picking from an array of sprites, scrolling in sync with the floor texture and disappearing when going out of the camera’s view.


Here you can see how the layers are working (I exaggerated the Z index of the ground to make it easier to see.


Basically, I have a spawner offscreen and it’s aligned with the ground. Each of the objects has a Rigidbody2D and when it’s created I simply apply a constant force to it so it move in sync with the ground animation.

One last thing, I noticed some bad stuttering when the objects scrolled across the screen. To fix this I set the Interpolate setting on the prefab’s Rigidbody2D component in the Inspector.


Subscribe To My Mailing List

Want to learn how to make a game? Not sure where to start? Even if you are a seasoned game maker there is still a lot you can learn from my mailing list. I'll be covering tips and tricks for how to build, release and market games each month.

Simply sign up for my mailing list and also get access to a 50% off discount code for my eBooks and other content. I promise to not spam your inbox!

Join Now