I’ve been waiting for camera follow for weeks, I know I could have googled it but there were other priorities and hand ins going on. With this I can finally expand the size of the levels. However once I saw how small the code was I felt stupid and should have googled it after all, or just had a stab at doing it myself.
Yup thats it. The one feature I’ve been waiting for, is simply one variable and one function, simple! We keep the camera position updated every frame to match the position of the ship and maintain its Z distance away from it, great bit of script to keep around and remember, would be really useful for platformers as well.
Now I had to flesh out a level. Before I had some terrain with collisions above and below, with a collectable star that required picking up before the player could exit the level, however the sides were open and you could float out into space and never return. That idea needed to be created on a larger scale to accomadate for player movement and for the environment to barricade the player into the level. I present to you, the end result.
Okay changes made are:
- Fully contained level (more assets from kenney.nl)
- Multiple star pickups before level can be exited
- Additional asteroid obstacles
- A scrolling background of stars (this slowly moves even if the player is stationary)
- Coloured the goal to make it more unique (still needs to not be an asteroid in the future)
- Spaceship now had a thruster animation using a particle emitter
The extra landscape was all drag and drop in, change the size and add colliders so nothing new to report on. The additional asteroids are prefab clones of the original, with direction, speed and rotation altered for variation and the goal asteroid was tinted in Unity. That covers all of the simple changes.
I’ve never had a background on my scene this entire time, mainly because I wasn’t sure what would happen once we added a camera tracker or what kind of scene I’d end up with. Maybe the exercise could have ended up as a long side scroller like R-Type or Gradius. I turn to Kelly (the wife) who is sitting there with a textured rotating carousel behind the scene and remember why I’m the artist and shes the technical one. Naturally I coaxed her into going through the creation of one step by step.
Its kind of beautifully simple when you break it down. It is literally a textured cylinder with a modified version of our rotation script to add the other axis. Which spins around forever in the back of the scene.
All axis were thrown in there as a public float, so this now could be used for almost anything that needs to spin in any direction. Wish I’d thought of it!
As for my multiple star pickups. I’d placed all the stars, they all had the pickup tag from the last exercise and I tested multiple times to see if I could collect them all within the time limit. I ask another student to test it, they pickup one star, hit the goal and level complete. Brilliant planning on my part, just missing the code to make it work. Another student had worked out a way to auto complete the level on the pickup of all stars however I wanted all pickups and a goal location. From a combination of their code, the old roller ball tutorial, some banging my head off the desk and finally help from Kelly and Ant, this was produced.
Now all the star pickups are placed into a list, once entries in the list are below one and the goal is collided with, the player teleports to next level. Brilliant, feature implemented!
There was still time left in the lesson so I jumped onto moodle and dug through some of Ants previous video tutorials. I had seen a ship thruster video a few weeks back and decided to try and implement it. There wasn’t much to it outside of tweaking a few settings and parenting it to the ship. Towards the end of the video it covers turning off the emitter when the ship is stationary, I didn’t make it to this section so for now our little spaceship is burning a lot of fuel!
Sadly this is it for class time on the 2D Spaceship project. Its now almost Xmas, assessments due next week and then programming gets math heavy come new year (trying to scare us all over the holidays). I’ll have to add a few more levels to this in my spare time otherwise I’ll never get piece of mind that I finished!