460 likes | 608 Views
SE 320 – Introduction to Game Development. Lecture 11: Animations and GoKit Lecturer: Gazihan Alankuş. Please look at the last slides for assignments (marked with TODO ). Topics Today. Revisiting animations Using Animations Using GoKit. Moving Things in Unity. Manual. Animations.
E N D
SE 320 – Introduction to Game Development Lecture 11: Animations and GoKit Lecturer: GazihanAlankuş Please look at the last slides for assignments (marked with TODO)
Topics Today • Revisiting animations • Using Animations • Using GoKit
Moving Things in Unity Manual Animations Setting position/rotation in the Update() function Applying forces/setting velocities in the update function Creating animations in Unity’s Animation pane Creating animations in the modeling software Position-based Physics-based In Unity In Blender, etc. Tedious, have to keep state and do something every frame Things can go out of control, most motions are not physically viable Static motions, cannot adjust easily in runtime
Deciding how to move things • All methods have their pros and cons, you have to decide for your situation • Animations are great for most cases • In week 8, we have learned how to create animations in the Unity editor • Let’s see how we can use animations coming from a model created in Blender • Models from 3DS Max and Maya are similar
Using animations created in Blender • We have a model that was created in Blender. • It has a number of animations in asingle timeline, one after the other
Using animations created in Blender • Now we would like to use this in Unity • Select the .blend file and the textures, drag them together to the Assets folder or Project pane • You can also dragthe folder that contains them
Using animations created in Blender • Now you see a prefab-like entry in the Project pane. You should see the textured robot in the inspector when you select it.
Using animations created in Blender • You can drag it into the scene and run the game. You’ll see it doing some motions one after the other • These are the animations that are in the timeline of the Blender file. We need to separate them and name them.
Using animations created in Blender • The artist that created the animations (yours truly) told us which frames contain which animations: • 1-20: Walk • 30-50: Damage • 60-100: Rejoice • Now we want Unity to know them as well. Select the model in the project pane and look at the inspector.
Using animations created in Blender • There you will see import options for this Blender file. Under Animations, we want to add all the animation segments
Using animations created in Blender • We add them and name them accordingly. We can set them to loop if it makes sense. • Don’t forget to press the Apply button on the bottom
Using animations created in Blender • Now select the robot in the hierarchy. In the inspector, under the Animation component, we see that Play Automatically is marked. This is why it was moving when we ran the game earlier. • When we run it now, it will only play the Walk animation. This is because the Animation property is set to Walk.
Using animations created in Blender • Under Animations property, we should see all three of the animations. We can set Animation to be one of the others and view them by running the game
Using animations created in Blender • Now disable Play Automatically and let’s start to initiate animations through the code
Starting animations in code • These are just like the animations that we created in Unity’s Animation pane in week #8 • Create a new C# script and add it to the robot. • Add the code below to create buttons that initiate the animations
Starting animations in code • Notice how clicking only once is sufficient for starting the animation. Similarly, your code should call the .Play() function only when it’s needed. • We have talked about this extensively in Week #8
Preparation for this week’s homework • At the end of the slide deck you will see more information about this homework. • Here we will go over the necessary steps for you to start working on the homework • Download this package: http://homes.ieu.edu.tr/~galankus/teaching/12fall/se320/material/day11/animhw.unitypackage • Create an empty Unity project and import the package
Preparation for this week’s homework • Play the game and observe that you lose health when you hit the arrows, the axe, spikes, etc. Jump to the other side and get rich.
Preparation for this week’s homework • Now let’s prepare to add our animation. • In Hierarchy, under 3rd Person Controller, remove Bip001 and construction_worker. Let the DamageReceiver stay.
Preparation for this week’s homework • Download the robot model from here: • http://homes.ieu.edu.tr/~galankus/teaching/12fall/se320/material/day11/robotmodel.zip • Extract it, then import the extracted folder into your project by dragging it into the project pane
Preparation for this week’s homework • When you select the robot model in the project pane, you should see the robot textured in the preview part of the inspector pane
Preparation for this week’s homework • Drag the robot model into the scene at the beginning of the level
Preparation for this week’s homework • Now we will make it work with the 3rd person controller. • Create an empty game object and drag it under 3rd Person Controller. Rename it “Offsetter” • Reset its transform component • We will use this to locate the robot without touching the robot’s transform, which is driven by animations coming from Blender.
Preparation for this week’s homework • Drag the robot under Offsetter • Revert the transform of the robot to prefab by clicking “Revert to Prefab”. This will ensure that we don’t compete with the transform values coming from Blender’s animations. • Finally, these transform valuesshould not be inbold
Preparation for this week’s homework • Now, when we run the game, we see that the robot is huge and sideways. • We will fix this using the Offsetter
Preparation for this week’s homework • Rotate and scale the offsetter so that the robot is smaller and looks at the correct direction.
Preparation for this week’s homework • From here on, it’s up to you to complete the rest of the homework. Take a look at the earlier parts of this slide deck for more information.
Limitations of Animations • Animating displacement is static. In code, I should be able to give a destination that I calculated, and an object should move there in a specific duration. • Tweening libraries • GoKit • https://github.com/prime31/GoKit • https://github.com/prime31/GoKit/wiki • http://prime31.com/unity/docs/#goKitDoc
Getting GoKit • Go to https://github.com/prime31/GoKit and download a zip file • Extract it to a folder. This is a Unity project.Open it with Unity.
Getting GoKit • Open the scenes in the Demo folder and play with them
Using GoKit • To use GoKit in your own projects, you just need to copy the Editor and Plugins folders into your own project • Let’s create a new empty Unity project and copy these folders from the GoKit-master project into our project.
Using GoKit • Let’s create a cube, a c# script "CubeScript" and attach the script to the cube. • Create a directional lightand align the camera to view • When you run the game, nothing happens, yet.
Using GoKit • Add the code below to the script. When you run the game and press the button, you will see the cube move to (5, 0, 0) in 3 seconds. • Notice how GoKitadded new functions to the existing Transformclass • Run it and see the cube move
Using GoKit • Take a look at the GoKit Code Basics page in the GoKit wiki: https://github.com/prime31/GoKit/wiki/1.-GoKit-Code-Basics • Instead of calling extension methods such as transform.positionTo(), you can also do this • Go.to(someTransform, duration, someTweenConfig) • This way you have more control over the configuration of your tween.
Creating Tween Configurations • Try this code, it will move the cube, make it smaller and make it red, simultaneously in 3 seconds. • The TweenConfig class encapsulates these operations.
Using GoKit • You can tween any property you see in the components. For example, lets move it by changing the position property by name: • Instead of transform, you can use any other component and any property that they may have. It behaves as if you are changing the property using the inspector.
Using GoKit • You can shorthand the config creation if you want. The two code pieces below are equivalent.
Using GoKit • You can also chain tweens one after the other, or place them in different points in time, using TweenChain and TweenFlow classes
Visual Path Editor • GoKit includes a visual path editor that you can create paths composed of spline curves • You can create these paths visually, or you can supply the points in runtime • Let’s see how we can use the visual path editor
Visual Path Editor • Create a folder named StreamingAssets in your project. This is where GoKit will save pathfiles. • Create an empty game object and drag the GoDummyPath script onto it
Visual Path Editor • When you select this GameObject, you will see some new markers in the scene. • You can drag these to set the begin and end of the path. • You can double click on them to create new points for the path
Visual Path Editor • Once you’re done, name your path and save it using the inspector. • The file in StreamingAssets folder contains information about this path. • If you don’t want to create any new paths, you can remove this GameObject.
Visual Path Editor • Here is how we can play this path in our code
Visual Path Editor • When we run the game, we see that the cube follows the path nicely
TODO: Homework • Start with slides 17-28 here. • Using Blender animations • Make the robot play the Walk animation while it is moving. Stop it when it is not moving (handle input independently in your script) • Make the robot play the Damage animation when it receives a damage • Make the robot play the Rejoice animation when it reaches the gold. Play it only once. • Using GoKit • Change the red balls so that they hit the character like a homing missile • Add another ball cannon that shoots green balls that go in a predefined path that looks like a wave • Get Özkan to grade your work, according to http://homes.ieu.edu.tr/~osayin/gd/homework_policy.html • ozkansayin.ieu@gmail.com(NOTE THE ADDRES CHANGE!) • Subject (paste this): SE 320 Homework 11 • What to send: • Assets -> Export package • File -> Build Settings -> Web player -> Build (for both games) • DUE DATE: Dec 11