Road Runner was made as part of my Gameplay Scripting Module in Year 1 at Teesside University. Over the course of the module, I was required to produce 3 prototypes in either Unity or Godot. This module allowed me to learn and apply C# scripting to achieve my prototypes.
For this Third Prototype, I was required to script a short, repeatable game, based on two words chosen by me, that made use of procedural generation. I chose 'Road Runner', an automatic side-scrolling platformer game which procedurally generates platforms as the camera moves.
This script starts by calling a Loop() Function. This function adds the delta time to the TimeUntilLoopFin [Float]. The LoopTimer is a public variable, which means it can be changed in editor, for the purpose of this timer, I set it to 2.0.
Because the Loop() function is within the Update() function, it is automatically fired once per frame. As a result, the delta time is added once every frame, until the TimeUntilLoopFin is greater than or equal to the LoopTimer.
This fires the GeneratePlatform() function and resets the TimeUntilLoopFin.
When called, the GeneratePlatform() function selects a random number within a range. The resultant number then instantiates a specific Platform Prefab, which can be set within the editor. For example, PlatformPrefab[0] is the Double Stop Sign.
These platforms instantiate at a spawn point that moves alongside the camera.
To help achieve this, I used this online video to help:
https://www.youtube.com/watch?v=vClEQ1GqMPw [accessed 17/04/2025 @ 11:07]
To start, I created a public float variable that sets the speed for the camera scroll. This can be edited in the editor.
I then created a Vector3 that stored the current position of the Camera every frame. This allowed me to access the x position of the Camera and add it to the CameraSpeed.
Finally, I set the Camera position to the updated CameraPos Vector. This enables the Camera position to change each frame.
One issue I noticed after building the project, is that the Camera moved quicker in editor than it did in the application. Although I can't say for certain why this is, I suspect it would be caused by a differing framerate between the editor and the built application.
To help achieve and understand this, I used this forum from stackoverflow:
https://stackoverflow.com/questions/44468749/trying-to-get-camera-in-unity-2d-to-automatically-scroll-not-follow-the-player [accessed 28/03/2025 @ 10:33]