First, I used the website goxel.xyz to create the main duck model. I also made a chicken model, which was designed to replace the duck, but ended up being part of the environment.
I wanted to use the colours I had applied to it, but unity would never except the material.
Next, I made the textures for the game. I needed a grass and road texture that was seamless, so I used guides in gimp to make sure the edges started and ended in the same place, so the texture didn’t look wrong when repeated several times.
I then set up a nice environment using these textures and some textures from another task, and a simple tree model from a cone and a cylinder.
To make the player move, I applied a rigidbody to the duck and used GetComponent to store the rigidbody so I could use it. I then used AddForce, which would be applied to the duck after the Fire1 input is pressed, which defaults to left click and left ctrl. I used a public Vector3 to control the force added in the editor so I could adjust it to an appropriate jump. However, this did not initially work, as I had to add a box collider to the duck and adjust it so it's feet didn't phase into the floor.
Also, with this method, the duck doesn't jump, but rather ascends in the sky. To combat this, I made a function which changes the private Boolean canJump to true. The jumping script is only allowed to execute when canJump is true, so canJump defaults to true, but after adding the force, canJump is set to false and the function is invoked, but with a delay of 0.8 seconds. This way, the player has to wait 0.8 seconds between each jump.
The camera know needs to follow the duck, so I made a script very similar to the player movement and made a public integer which changes how much the camera moves every jump
.3. Obstacles
Using the car model as detailed earlier, I put a continuous force component and a rigidbody on it to get it moving. I then made the car a prefab, making it easy to place and use in the engine. After making the cars move, I then used the OnCollision function to define that when the duck is hit, it will restart the scene. To do this I had to include the Unity Scene Manager and used SceneManager.LoadScene. So the script could distinguish between the different objects that collided with it, I tagged the car prefab with the tag "car"
I then made a new script to handle the car instancing. I used InvokeRepeating to make it repeat the function handling spawning called Spawn every 3.5 seconds. In this spawn function, I used instantiate to create an instance of the car based on spawner gameobjects as selected in the editor, using it's rotation and position, but with a random offset to give the game variation
.4. Final Improvements
To make the game more replayable, I added random car speeds using a brand new car speed script. This script used the rigidbody of the car and the addForce function, which I gave the x value a random value between 800 and 1000. To make the game run smoother, I also make the instances destroy themselves after 5 seconds, instead of it just infinitely spawning cars
.I also added a delayed restart, so the duck gets hit and the car pushes it for 1 second before restarting. I did this by unfreezing rotation and enabling gravity on the duck, and then counting each frame in a variable until it reaches 60, as its 60 fps, and using SceneManager to LoadScene. Finally, I built my game and recorded it as seen below.