Unity Learn home
View Tutorial Content

Environment and Player

Tutorial
Beginner
+10 XP
25 Mins
(758)
Summary
The Roll-a-ball Project is a simple rolling ball game that teaches you many of the principles of working with Unity.
The 2nd of 4 tutorials in the project demonstrates how to create a new Unity project, add some "primitive" shapes, and create a new material to change the color of the shapes. Then, we implement physics and add a simple C# script to let the player control the ball with the keyboard.
Roll-a-ball tutorials:
  1. Environment and Player
Select your Unity version
Last updated: April 12, 2023
2019.3
2019.2
2019.1
2018.4
2018.3
2018.2
2018.1
2017.4
2017.3
2017.2
2017.1
5.x
Language
English

1.Setting up the Game

Creating a new project and setting up the basic game.
This content is hosted by a third party provider that does not allow video views without acceptance of Targeting Cookies. Please set your cookie preferences for Targeting Cookies to yes if you wish to view videos from these providers.
Type caption for embed (optional)


2.Moving the Player

Moving the player object using player input and physics forces.
This content is hosted by a third party provider that does not allow video views without acceptance of Targeting Cookies. Please set your cookie preferences for Targeting Cookies to yes if you wish to view videos from these providers.
Type caption for embed (optional)

This is the current state of this script, as of the end of this lesson. This script will continue to change and mature in later lessons.

PlayerController

using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public float speed; private Rigidbody rb; void Start () { rb = GetComponent<Rigidbody>(); } void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); rb.AddForce (movement * speed); } }

Project:
Roll-a-ball (Deprecated)
Environment and Player
Environment and Player
General Tutorial Discussion
1
17
1. Setting up the Game
1
2
2. Moving the Player
22
43