How to Make a Game with Visual Scripting

Getting Started with Unity 2021 - No Coding Required

15 min read 275K+ views Apr 8, 2021
Part 1 of 5 - Visual Scripting Series

This is Part 1 of a 5-part series on making your first game with no code using Visual Scripting in Unity. By the end of this tutorial, you'll have a scene with player movement and a camera that follows your player.

1 Prerequisites

Before starting, make sure you have:

  • Unity 2021 or later - Visual Scripting is built into Unity 2021+. If you're using an older version, you'll need to import the Bolt package separately.
  • Basic familiarity with the Unity interface

2 Creating a New Project

Start a new 3D project in Unity Hub:

  1. Open Unity Hub and click New Project
  2. Select 3D as the template
  3. Name your project (e.g., "The Cube")
  4. Click Create

3 Setting Up the Scene

Creating the Ground

  1. In the Hierarchy, right-click and select 3D Object → Cube
  2. Rename it to "Ground"
  3. In the Inspector, find the Transform component
  4. Set the Scale to: X: 15, Y: 1, Z: 1000

Creating the Player

  1. Add another Cube: 3D Object → Cube
  2. Rename it to "Player"
  3. Move it above the ground using the Y-axis arrow (or set Y position to 1)

Adding Color to the Player

  1. In the Project window, right-click in Assets
  2. Select Create → Material
  3. Name it "Player Material"
  4. Click the color swatch and choose red
  5. Drag the material onto your Player object

4 Adding Physics

To make the player fall with gravity:

  1. Select the Player object
  2. Click Add Component in the Inspector
  3. Search for and add Rigidbody

Press Play to test - your player should now fall onto the ground!

5 Creating an Obstacle

  1. Select the Player and press Ctrl+D to duplicate
  2. Rename the duplicate to "Obstacle"
  3. Move it forward (positive Z direction)
  4. Create a new material with a light gray color
  5. Apply it to the Obstacle

6 Visual Scripting Setup

Now let's add movement using Visual Scripting:

  1. Select the Player
  2. Click Add Component → Script Machine
  3. For Source, select Graph
  4. Click New and name it "Player Graph"
  5. Click Edit Graph
Understanding Events

The graph comes with two events: Start (runs once when the game begins) and Update (runs every frame). For physics, we'll use Fixed Update instead.

7 Adding Forward Movement

  1. Right-click in the graph and search for "Fixed Update" - add it
  2. Search for "Rigidbody Set Velocity" - add it
  3. Connect Fixed Update's output to Set Velocity's input
  4. For the velocity, we need to create a Vector3:
    • Search for "Create Vector3"
    • Set Z to 20 (forward speed)

Fixing Gravity

Setting velocity directly resets gravity. To fix this:

  1. Add "Rigidbody Get Velocity"
  2. Add "Vector3 Get Y"
  3. Connect the Y value to your Create Vector3's Y input

8 Preventing Rolling

Your player might roll due to friction. To fix this:

  1. Right-click in Assets → Create → Physic Material
  2. Name it "No Friction"
  3. Set Dynamic Friction to 0
  4. Set Static Friction to 0
  5. Set Friction Combine to Minimum
  6. Drag it to the Player's Box Collider Material slot

9 Adding Side-to-Side Movement

  1. In the graph, add "Input Get Axis"
  2. Set the axis name to "Horizontal"
  3. Add a Multiply node, multiply by 10
  4. Connect the result to the X value of your Vector3

Now you can use A/D or arrow keys to move side to side!

10 Using Variables

Let's make the speeds adjustable from the Inspector:

  1. In the graph, go to the Object variables tab
  2. Add a Float variable named "Forward Speed" with value 20
  3. Add a Float variable named "Side Speed" with value 10
  4. Drag these variables into the graph and connect them instead of hard-coded values

11 Camera Follow with Cinemachine

  1. Go to Window → Package Manager
  2. Select Unity Registry
  3. Search for Cinemachine and Install
  4. In Hierarchy: Cinemachine → 2D Camera
  5. Drag the Player to the Follow field
  6. Adjust the camera rotation and distance as needed

Changing the Background

  1. Select the Main Camera
  2. Change Clear Flags from Skybox to Solid Color
  3. Choose your preferred background color

What's Next?

In Part 2, we'll cover:

  • Detecting collisions with obstacles
  • Restarting the level when you lose
  • Creating a finish line
  • Collectible coins with saved variables
Next: E02 - Gameplay Loop

Learn to create win/lose conditions and collectibles

Continue