Snowboard Game: The Dude Board

Emre Baskak
5 min readDec 24, 2022

--

Game No 2: The Dude Board!

Snowboard Game: The Dude Board

It is a one-level 2D snowboard game that I created via Unity and C#.

To play the game on the web, please click the link below:

Snowboard Game: The Dude Board

The Dude (our character) slides down to the mountain on his snowboard while trying not to fall down. If he reaches the finish line, he wins!

What if he falls down? No problem! He starts all over again!

As Samuel Beckett said once:

“Ever tried. Ever failed. No matter. Try again. Fail again. Fail better.”

I’ll be writing some of the key methods and game mechanics that I learned to create this game.

Edge Collider

I used a closed sprite shape to create the mountain in this game. Then, I added an Edge Collider 2D so that I have a collider all along my sprite shape.

Dynamic Sprite

Right click on an empty space in Hierarchy. Hover over 2D Object, then Physics, and select Dynamic Sprite. Now you have an object that already has a Circle Collider 2D and Rigidbody 2D.

Cinemachine Follow Camera

It is a package for dynamic, smart, codeless cameras. Multiple cameras can be managed in the scene and rules can be created easily for these cameras.

Click on the Window on the menu, then select Package Manager.

Select Packages: In Project to Unity Registry. Scroll down to find Cinemachine or simply search it in the search bar. Then install it.

Right click on an empty space in Hierarchy, hover over Cinemachine, and select Virtual Camera.

In Virtual Camera’s Inspector, chose an object to follow. And change Body to Framing Transposer to frame a particular thing in our game.

With Screen X and Screen Y values (in Inspector under CinemachineVirtualCamera component) you can play with the position of your camera in the scene.

Surface Effector 2D

It creates a force along the surface of the colliders so that the object touching the surface moves with a speed. It is added from the Inspector as a component. Then in the relevant collider, you can select “Used By Effector” option. You can decide on speed in Surface Effector 2D component in the Inspector. “Force Scale” in the component is how much force you apply against gravity. If you pull it down to 0, you’ll see the character is not moving. If you pull up to 1 let’s say, you can see it moving.

P.S. When the character slides down the mountain in this game, sometimes he falls down right in the mountain. To prevent that click on the character, and find Collision Detection in its Rigidbody in the Inspector. And change it from “Discrete” to “Continuous”.

AddTorque()

First, we need to grab the Rigidbody 2D in our script, because Rigidbody makes objects respond to physics in Unity.

AddTorque()

SceneManagement

When our character falls down over his head, we need to reload the scene so that players can play the game again. For that, we need to use a namespace called SceneManagement.

SceneManagement

In the codes above our first game scene is re-loaded when the player collides with any other object (either his head collides with the ground or the player itself collides with the finish line in this game).

Invoke()

When the player collides with any other object, the game is re-loaded right at that moment. For a better game experience, the scene should be loaded after some time passed with the collision. So that player sees and feels clear that he has failed or won.

There to approaches for that: invoke and coroutines.

So, we can write the code above in this way:

Invoke()

Particle Effects

Right click on an empty space in Hierarchy. Hover over Effects and select Particle System.

The particle system is already a component that is added to game objects. So you can also click on your game object, and on the Inspector that is opened, you can click on Add Component button to add the Particle System.
P.S. Particle System is a game object itself. But particles themselves that are seen in the game are not game objects.

In the component itself, you can decide on the duration, start size, start speed, or color of the particles.

In the Emission section of the component, Rate over Time decides how many particles will be produced in a second.

So let’s say that our Rate over Time is 100 and our Duration is 0.1. In this case, 100 * 0.1 = 10 particles will be released.

In the Renderer section of the component via clicking Material, you can choose what kind of particles will be produced.

To activate our particle effects with code;

Activation of particle effect in a script

If we want to stop particle effect playing we can simply use Stop() method instead of Play().

FindObjectOfType

GetComponent is used when the searched component is on the same object. If the searched component is on different object FindObjectOfType is used.

P.S. FindObjectOfType is used if there is only one of that thing in the scene. There has to be only one, so that there is no room for confusion.

To be able to use it in our script, first we need to create a variable in our class. Then, we find it in our Start() or Awake() methods.

Let’s say that we want to reach SurfaceEffector2D that is in another object;

FindObjectOfType<>

With the code above, we reached the SurfaceEffector2D which was in another object, then we reached its Speed field and updated it to be 50.

Sound Effects

Click on the game object to open the Inspector. Then, add Audio Source component. You’ll see an AudioClip field in the component. Drag and leave your audio clip there. Do not forget to unclick Play On Awake field.

Let’s say that in our object, we added Audio Source component and we want to play it in a method. Then in our method, we would write;

Playing a sound effect

or we can also use [SerializeField] to be able to play different sounds. For that, we don’t drag a sound clip to Audio Source but we drag and add it to the SerializeField on Unity under our script.;

Another way of playing a sound effect

--

--