Tutorial 2 - 3D Models in Unity


Tutorial 2 - 3D Models in Unity

To start this tutorial, I exported my previously made 3D character from Blender as a .FBX file. I decided to just import this file into my previous project that I was working on in the last tutorial. Once added to the assets folder for this project. I opened the character file in the project window in unity and viewed the animations.

I then ticked the box for 'Loop Time' on the Character Idle and Walk animations, and I decided to not loop the Character Wave animation as this would be just activated by pushing the space bar later for one animation loop. I then adjusted the start and end times for each animation with the previously set Blender number in the action editor and matched them for each animation. A screenshot can be seen below of the Inspector window:

Character in the Inspector showing Animations

I clicked on the 3D character and extracted the materials, followed by saving the texture file for the 3D character into my assets folder for this project, and added the texture to the extracted material for the 3D character by selecting Base Map.

Materials in the Inspector

The next step was to drag the object into unity scene, and add an Animator into the Assets panel, which enabled opening up the Animation State Machine. Then I dragged each Animation from the Assets window into the State Machine window and set the Idle to default. I then setup the transitions between each animation. Then I setup one of the parameters the Wave parameter. It was added as a trigger. Then by clicking on the Wave transition under the conditions in the inspector, Wave was selected, the return transition to idle required no Conditions parameter.

A script was setup to trigger the Wave animation by pushing the Space bar, a screenshot can be seen below:


Wave script

To control the character a new script also had to be added, which when the script is added to the character creates a Character Controller object. The height, center and radius of the control was adjusted by turning on the Gizmo in Unity and adjusting, it later required testing and adjusting to get the Player height right when walking.

My Third Person Controller script

This character controller script was also added to the character in order to control using the vertical and horizontal, for turning, and moving with the W/S keys:

Character Controller script

The next part of the tutorial was to look at Unity Events. I added a Box Collider to the character object and set it to be a trigger, this was to stop it interfering with the character controller. The characters object tag was also set to "Player" and a Rigidbody component was attached.

I then created a cube and rescaled it into a door sized object. Next an empty GameObject with a box collider (trigger) was setup and placed over the door area, which could be used to detect the player when it hits the box. A script was made and added to the empty GameObject which was the Trigger Detection script, then the Door Object dragged from the scene list into the inspector. Once the script was setup, in the inspector an action was added and GameObject > SetActive was selected. This way when the Player entered the empty GameObject the door would disappear. The script also includes some code which could be used to count the number of times the Player entered the empty GameObject box. A screenshot of the scene and script can be seen below: 


Screenshot of scene with empty GameObject and Door


Trigger Detection script

For the tutorial exercise, I needed to setup the walking animation to trigger whenever the character was walking. I chose to use a Boolean parameter rather than the Float parameter. The character will walk whenever the W key is pushed down. The Walk script and the state machine details can be seen below:


Walk script

Conditions: Walk is true


Conditions: Walk is false

Once I had setup the script, parameters and conditions, I had to adjust the Character Controller height, as the character was walking slightly below the surface. Just some adjusting of the height was able to get the character set to the correct height on the ground object. A screenshot can be seen below where I was adjusting the height in the inspector once clicking on the character.

Character Controller window


Character Idling, Waving and Walking.

Leave a comment

Log in with itch.io to leave a comment.