Coquitlam >> UN501 >> 9:10 am - 10:10 am

12/02/2018 - Jimmy Randa
Hi everyone!

Today we worked on making a door that can open when we press a button. We also added a portal gun as a viewmodel to our game.

Have a good week!

12/09/2018 - Jimmy Randa
Hi everyone!

Today we worked on making a cube, that we can pick up when we press "e" and move it around the map with us, then drop it somewhere. We also made the cube work with our button from last class.

Have a good week!

12/16/2018 - Jimmy Randa
Hi everyone!

Today was a work week to finish everything up we're working on.

Have a great Christmas break!

11/04/2018 - Jimmy Randa

Today we learned how to make our character die and respawn. We added a respawn GUI as well with a button to click to respawn at the start of the level.

Have a good week!

11/18/2018 - Jimmy Randa
Hi everyone!

Today we learned how to win our level, and get sent to the next level. We also added walls that we cannot shoot portals onto.

Have a good week!

11/25/2018 - Jimmy Randa
Hi everyone!

Today we polished up our portal placement system, and polished up rotations. We added a GUI for winning the level, and we got the rest of the class to work on the next level.

Have a good week!

10/14/2018 - Jimmy Randa
Hello everyone!

Today we added a camera to our Portals so we could see through them. We used a Render Texture and applied it to the two different camera in our portals. We then made a new material and put it on a cube inside our portal.

Have a good week!

10/21/2018 - Jimmy Randa
Hi everyone!

Today we made a few changes to our movement code so that it would be better and we wouldn’t be floating. We used a character controller and made two new scripts for Camera movements and player movements.

Next Week we’ll work on levels again.

10/28/2018 - Jimmy Randa
Hi everyone!

Today we learned about importing 3D Models into our games. We found some spikes off the internet in a .fbx file format, and dragged it into our unity assets. We are able to use an FBX just like a regular gameobject and put a box collider on it.

Have a good week!

09/09/2018 - Jimmy Randa

Welcome to the new semester! My name is Jim and I'm your instructor for Unity 401. I'll be using this page to post summaries of what we learned in class, it'll include all the scripts and code we went over too. I'll also be posting optional homework / bonus assignments that you can do at home!

Make sure you’re also bringing a USB drive to class!

Today we went over some review, we went over the unity work space, how to stay organized, and a few keyboard shortcuts.

The workspace goes something like this:

• The hierarchy contains everything that’s in our scene – it keeps track of everything we put into our game, also known as “Game Objects”.
• Scene view is where we can edit out games levels
• Game tab shows us what our camera can see. This is what the player sees when playing their game.
• The inspector shows us properties of a selected Game Object.
• The asset window is where we keep all of our assets nice and organized! Anything in this window can be added into our scene. Just remember that if something is in the assets window, it does not necessarily mean it’s in our game yet!
• The console tab shows us errors in our code, or things we print from code!

Last for review, we created folders in our assets window to stay organized.

Next, we started working with the Unity terrain editor to create a world to play on. Terrains are like the surface of the earth, you can raise and lower different parts of the Terrain!

Right click on the hierarchy, click on “Create”, “3D Object”, and “Terrain”.

Look around in your world, you should see a large white plane in your scene. Because this time we’re making a 3D game, navigating in 3D space is a little different from our 2D games. Hold right click and use WASD to maneuver your camera like you would a game character.

Select your terrain in the hierarchy, and in the inspector window you should see its properties. There are several tools in the terrain’s inspector that we’re interested in. “Raise/Lower”, “Paint height”, and “smooth terrain”.

We spent a large portion of class working on sculpting our terrain.

Next, there’s another tool in the terrain’s inspector called paint texture. Select it, and find another button that says “Edit Textures”. A window will pop up for you to select a image to use as a texture. This can be any image you want, but I got us started with a grass texture. Click the select button under Albedo (RGB) and choose the grass texture image.

If you want to find more textures, try Googling things like “Grass texture”, “Sand Texture”, “Rock Texture” and so on.

Now that we created our texture in our terrain, we have the ability to paint it on. We spent the remainder of class painting our terrains with various textures.

Next class we’ll work on adding a player to our game!

09/16/2018 - Jimmy Randa
Hey everyone!

In our second class we made a player that could travel along our terrain!

We started by right clicking on the hierarchy and selecting, “3D Object”, “Capsule”.

Rename the capsule in the hierarchy to “Player” to stay organized.

Something that’s great about 3D games is that most gameobject we’ll add to start with come with colliders already! For example, our newly added capsule has a component in it’s inspector called “Capsule Collider”, and our terrain has a “Terrain Collider”.

We just need to add a Rigidbody (Not Rigidbody2D) to our capsule so it has physics. Select the capsule in the hierarchy, and in it’s inspector window click add component and find Rigidbody.

Remember – colliders are for detecting when 2 gameobjects hit each other, and doesn’t allow them to go through each other. Rigidbodies add physics to your game object, so it can respond to things like gravity and other forces.

Next, we set up our player’s camera so that it will follow our player as we move it around.

Click and drag your camera in the hierarchy on top of your Player that’s also in the hierarchy. Once you let go, the Main Camera should now be indented below the Player. This signifies that it is inside. Click on the main camera and set the Transform Position X, Y and Z to 0, 0, and 0 in the inspector. This will center it to our player.

Next we made a script for our Player. We started with some basic movement:

public float speed = 5f;
If (Input.GetKey(KeyCode.W)){
transform.Translate(Vector3.forward * speed * Time.deltaTime);

And I got you guys to try to make the rest of the directions yourselves. The other directions were back, left and right.

Next we did jumping, which looked like:

GetComponent<Rigidbody>().AddForce(Vector3.up*5, ForceMode.Impulse);

Lastly, we made it so we could pan our camera while playing the game. The mouse will be locked to the center of our screen, and movement will control panning. We started with 2 variables at the top to store how much we’ve moved our mouse in each direction:

float lookHorizontal = 0;
float lookVertical = 0;

then inside of update below our movement code we added:

lookHorizontal += Input.GetAxis(“Mouse X”);
lookVertical += Input.GetAxis(“Mouse Y”);
transform.eulerAngles = new Vector3(-lookVertical, lookHorizontal, 0f);

If we saved and tried to play now it works but our mouse hasn’t been locked to the center of the screen. We came back to our script and added some code into the Start() function.

void Start(){
Cursor.lockState = CursorLockMode.Locked;

Unity has this premade variable called lockState that controls whether or not the cursor is locked to the center of the screen. Your mouse should now disappear when playing your game.

Next class we’ll work on adding enemies to our game!

09/23/2018 - Jimmy Randa
Hello everyone!

For our third class we added enemies to our games. Simple ones who would chase us if we got too close, then knocked us backwards.

For our enemy, we used another capsule. In our hierarchy we created a capsule, and renamed it “Enemy”

Make sure you add a rigidbody to the enemy, open the constraints tab on the rigidbody and freeze rotation X and Z so our enemies stay upright as they chase us.

Next we need to tag our enemies, so we created a custom tag and named it “Enemy” then applied it to the enemy.

The last thing we did was differentiate the enemy from our player, because they both look the same right now. We coloured the enemy red by creating a red material and applying it to the capsule.

To create a material, come to your assets folder, right click, and click on “Create”, “Material”. Name it “Red”.

Click on the material in your assets folder, and head to the inspector. Beside Albedo, click the white rectangle and change the color of the material to red.

Drag your newly made material onto your enemy.

You can also create many more materials for other gameobjects in your game, and include textures.

Next, we made a script for our enemy and started to add code that looked like:

GameObject player;
void Start(){
Player = GameObject.FindGameObjectWithTag(“Player”)

This code stores a GameObject, in particular we search for our player in the game, and store it in the variable.

Next, inside of update add the following:

void Update(){
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, 3*Time.deltaTime);

This line is very long but what it does is quite simple. It says, move from our current position to the player’s position and move at speed 3.

Next, let’s make the enemy knock us back when he touches us. Add the following code to your script, below the update function:

void OnCollisionEnter(Collision coll){
if(coll.gameObject.tag == “Player”){
coll.gameObject.GetComponent<Rigidbody>().AddForce(Vector3.forward * 50, ForceMode.Impulse);

This code only runs when a collision is detected between colliders. For example, our enemy’s collider and our player’s collider touch, so the code is ran. The code then adds a force in the opposite direction as a knock back effect.

Come to your Player’s inspector window and in the rigidbody component change the “Drag” to 2.

Lastly, turn your enemy into a prefab by dragging it into the assets window, and add as many into your game as you’d like!

09/30/2018 - Jimmy Randa
Hey everyone!

Today we had a work block to design our levels. We learned about importing textures from the internet and turning them into materials so we could apply them to our GameObjects.

Have a good week!