Recap: Drone Pilot
Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 30 of 85.
This recap puts the chapter together: a direction built from the axes, made one unit long with .normalized, named directions such as Vector3.up, and a position changed through a copy.
Challenge
EasyFly the drone: the arrows steer, Space climbs.
- In
Update(), move it by the raw axes (Horizontal on x, Vertical on z),.normalized, timesspeed * Time.deltaTime. - While Space is held, add
Vector3.up * climb * Time.deltaTime; otherwiseVector3.downtimes the same. - Keep its y at least
0.5f, through a copy of the position.
Press Play and fly: it climbs on Space and sinks to the floor. Then Check.
Try it yourself
using UnityEngine;
public class Drone : MonoBehaviour
{
public float speed = 1f;
public float climb = 1f;
void Update()
{
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Unity Scripting Basics
1C# Basics in Unity
Hello, UnityVariablesDecimals Need an fText in the ConsoleVariables That RememberIf and ElseCompare NumbersRecap: Coin Collector2Make It Move
Place the CubeMove Every FrameTurn Every SecondSteer with the KeysRecap: Drive the Cube5Vectors
Adding VectorsDirectionsLocal and World SpaceDiagonal SpeedDistance Between ThingsVector3 Is a StructRecap: Drone Pilot8GameObjects and Components
References in the InspectorGet a ComponentMissing ComponentsAdd a ComponentRequireComponentShow and HideRecap: Light Switch6Transforms and Hierarchy
Parents and ChildrenHoist the FlagScaleLook At ThingsMove Toward a PointRecap: Orbiting Moon9Project: Catch the Star
The CatcherA Falling StarPractice on your own: Unity playground