top of page
  • Writer's pictureandreahywong

Player Control (CWC-S2020: Week 1)

Updated: Jul 18, 2020

Week 1: Programming a car on a road to avoid obstacles, familiarizing with Unity editor and workflow, and scripting basics in C#.

So far, this tutorial has been pretty impressively organized with the mass of material provided. Thought it'd be neat to leave some note-worthy point-form notes from this tutorial! Here's to organizing some of it in my brain (and computer)!


Unit 1

On this week's Unit 1 menu:


Essential content

Lesson_Plan_1.1___Start_your_3D_Engines
Download • 625KB

1.1 Start your 3D Engines

Some shortcuts in Scene view:

  1. Hold right-click + WASD = fly/rotate

  2. F = frame/focus on selected object + scroll wheel = zoom in/out + hold scroll wheel = pan + hold alt+left-click = rotate around object perfectly

  3. Ctrl + Z = undo most recent action(s)

  4. Hold Ctrl/Cmd + Move with Mouse = move object by whole units

  5. QWERTY = Toolbar Tools: Hand / Move / Rotate / Scale / Rect / Move, Rotate or Scale objects respectively



Customizing and Saving Custom Unity Editor layouts


Lesson_Plan_1.2___Pedal_to_the_Metal
.pdf
Download PDF • 474KB

1.2 Pedal to the Metal

  1. Adding Components to Objects

  2. Project > Assets > Folder organization

  3. Script components - creating a script to control the vehicle's movement using Visual Studio (one of many editors including Atom, Sublime, or even a basic Text Editor)

    1. classes = start with capital letters (e.g. PlayerController, MonoBehaviour, Transform = class vs. transform = access the transform component of an object)

    2. comments = for people to read and understand what's in the code (being with //)

    3. methods/functions = pieces of info for the computer to run a task

      1. semicolons (;) at the end of a method determine the end of a method

  4. RigidBody components - adding physics to objects and adjusting parameters including Mass (kg) and Gravity

  5. Ctrl + D = duplicate object(s)

  6. IDE (Integrated Development Environment) = a script-editing tool; "a piece of computer software that provides tools and facilities to make it easier to develop other pieces of software", e.g. when typing in Visual Studio, the IDE will suggest options/methods for your code

So, our vehicle drives forward automatically and has weight (as do the obstacles it drives into).

Lesson_Plan_1.3_High_Speed_Chase
.pdf
Download PDF • 285KB

1.3 Speed Chase

  1. Declaring Variables = piece of info that can vary/change in the format of: [access modifier] [data type] [variable name] = [variable value]

    1. Tip: initialize new variable (e.g. public float speed = 5.0f) (stores values)

    2. Can store different data types (e.g. game objects)

    3. new Variables inside a method are variables just in that method/line of code Tip: it's not great to have hard-coded values - it's better to create/declare a variable for these values

  2. Access modifiers

    1. private (can only be accessed from within that class)

    2. public (can be seen and used outside of its class, e.g. in Unity Editor))



Now, our camera follows the vehicle as it moves forward in a direction. However, it looks like it's attached underneath the vehicle.






Offsetting with a variable to adjust the camera position did the trick!





3. Edit > Preferences > Colors > Playmode tint (for more clear indication when in Playmode)

The rest of the Editor Interface now changes green when in Playmode (even on Pause, as Playmode is still active).

Lesson_Plan_1
.4___Step_into_the_Driver_s
Download 4___STEP_INTO_THE_DRIVER_S • 179KB

1.4 Step into the Driver's Seat

  1. Variable naming convention = start with lowercase letters for access modifiers, data types, and variable names (variables vs. Upper case for class, methods...)

  2. Edit > Project Settings > Input (different keys/inputs assigned to various Unity aspects. e.g. Horizontal/Vertical axes)

  3. Cleaning Up Script

  4. Cleaning Up Hierarchy with Empty Game Objects





The vehicle can now move sideways!




Now our vehicle actually rotates sideways/around obstacles like a normal vehicle would!

These movements here are actually controlled by key inputs (left/A and right/D keys) to control the movement of our vehicle - it's actually interactive!



So I think we have a working car that drives with player input, and has a camera that follows behind it! Onto the Bonus features!
29 views

Recent Posts

See All
bottom of page