12 Weeks with Unity: Week 6 - Physics & Third Person Controller

Apr 23, 2018 at 11:56 pm by -gToon


This is the sixth of a series of articles that cover my journey learning and exploring one of the most powerful indie game creation tools available - Unity. I’ll be sharing my knowledge and discoveries over a 12 week period. Each week I’ll post primarily on the process of learning Unity 3D along with other topics such as the history of the game engine, the community, and prominent artists/creators.

Last week I took a side trip into animating in Unity using Adobe Fuse and Mixamo. Fuse is a 3D character creation tool using sliders to adjust the look and shape of your character. Mixamo is a rigging and animation program in the cloud that allows you to rig the character you created in Fuse and add a variety of animations to it for use in your Unity scene.

I’ve been learning Unity using the Lynda.com course, “Unity 3D Essential Training” by Craig Barr as a guide.

Physics and Rigid Bodies

Another way to create animation in Unity is to use physics. For example, in the scene I’m working on in the 3D Essentials course, there is a hopper that comes down from the ceiling. A door opens in the hopper and a box drops on to a conveyor belt which then is dumped into a large bin.

By adding the component “rigid body” to the box along with a “collision” component. The idea is that the body of the box is how rigid and when you add a collision component it will react with any physics you set. Unity makes this very easy to do as all of these features are clearly labeled in the Inspector window to the right of the main screen

What is new to me in using Physics to animate something is the ability for materials to have physics attached to them. In the scene from 3D Essentials, the conveyor belt moves by changing the location of the material over time then looping the animation making it seem as if the belt is moving. Now we need to add physics to the material since we want the box to fall on the belt with a slight bounce and be moved to the bin where it falls in.

Again, Unity makes this process by adding a physics component using the Mesh Collider/Conveyor Belt and then the little radio button on the right which gives you access to all of the Standard Physics components. You have to have installed the free Unity Standard Components pack first though. In this case we choose “Bouncy” for our Physics emulator. 

Click the play button and the box drops on to the conveyor belt rides it down and falls into the bin with a bounce. All we need to do now is some slight adjustments to gravity and friction to make it perfect. We do this in the Inspector window on the right.

3rd-Person Controllers and Moving Around in the Scene

"With our scene in Unity set up and running with some animation now, we have animation in a couple of different ways, and we also have some physics happening here with our machine and some boxes falling. Now we want to start to interact with the scene with our character. So what we’re going to do in this is actually take advantage of a third person character view where we can see our character with a camera following behind that character." -Craig Barr, Unity 3D Essential Training.

Using the Standard Assets/Characters folder in Unity (be sure to import all of the Standard Assets or you won’t see anything). In the Characters folder, there is another sub-folder called Prefabs. In the Prefabs folder is a Third Person Controller set up. Grab that and drop in onto your hierarchy on the left.

Unity inserts the default “Ethan” character, but we want to add our own. This process becomes a bit more complex as we have to check the rigging and make some other changes to get it to work correctly.

What we do now is to drag and drop our HazMat guy character (part of the 3D Essentials course files) right on to the Third Person Controller in the hierarchy. Now we open up the HazMat guy folder and see that there is an avatar associated with the character. We want to drag the avatar over to the Inspector window and replace the Ethan avatar (make sure you have the Third Person Controller selected in the hierarchy). We then delete the Ethan files in the hierarchy and head over to the Inspector window to make some adjustments to our HazMat guy rig.

Mechanim, the animator in Unity, prefers a humanoid set up. We need to change the rig on our HazMat guy from generic to humanoid. With the HazMat guy selection, go to the Inspector and select the rig button. Underneath you’ll see a list of animation types, choose humanoid and hit apply.

At this point we need to configure the character’s rig, so hit the configure button and you’ll see the following screen: 

 

The HazMat guy is in a t-pose with his bone rig in green. If we were using our own bone set up we have to map it to Unity’s method of bone-naming. In this case, there are no problems (all bones are green; problem bones would be in red). On the right side at the bottom, you’ll see a ‘mapping’ button. Click it for a drop down and choose ‘automap’. Unity will fix any bone-related issues. Hit apply and then done.

Now when you hit the Play bottom (at the top) we move into the actual game scene and our character is now animating correctly using the WASD keys on your keyboard

NEXT: Setting up the Third-Person Follow Cam & Unity Asset Store






Top Stories

This website uses cookies to ensure you get the best experience possible More Info
Got it!