Game Programmingruttan/GameProg/lectures/unity0.pdf · Unity3d High quality game engine. Very nice...
Transcript of Game Programmingruttan/GameProg/lectures/unity0.pdf · Unity3d High quality game engine. Very nice...
Game Programming
Unity3dUnity3d
High quality game engine.
Very nice game editor
Terrain editor
Scripting in C#, JavaScript, Boo (dialect of Python)
Intuitive scene graph
Intuitive disk file system
Great documentation
Unity3dUnity3d
Unity Demos/TutorialsUnity Demos/TutorialsAngry Botscripting tutorials and others
Beginning Scripting and Intermediate Scripting: a good overview of C# and special Unity functions
Should watch all.Runtime Classes
Select UnityEngine/Classes
AssignmentAssignment Assignment: Complete
Learning the Interface Tutorial
Beginner Editor
Asset Workflow
Creating Scenes
Publishing Builds
Debugging
Debugging Tools
function Start () {
Debug.Log("Start called on GameObject "+gameObject.name);
}
function Update () {
Debug.Log("Update called at time "+Time.time);
}
Debugging
using UnityEngine;using System.Collections;
public class spin : MonoBehaviour { public float speed =10f; int count;
void Start(){ count=0; }
// Update is called once per frame
void Update () { transform.Rotate (Vector3.up, speed * Time.deltaTime); if (count%1000 == 0){ Debug.Log("Update called at time" +Time.time); } count++; }
}
Lighting & SkyBoxes
Lighting Class
SkyBoxes
Flares
Prefabs
It is often useful to have a number of duplicate items that edited and changed as a group. To do this one creates a Prefab object. Then all copies of that object can be changed by editing one of the group.
Asset -> Create Prefab
Drag object into prefab asset pane.
Animation
From asset store get Skeleton Pack
Drag weaponless skeleton to Hierarchy.
Assets →Import Package → Scripts → import
In Hierarchy →Standard Assets → Scripts → Camera Scripts → Mouse Orbit to Main Camera.
Animation
Drag Skeleton to Mouse Orbit Target
Press Play.
Set Mouse Orbit Distance, etc to taste.
Expand skeleton in HierarchyExpand Bio01
Click on skeleton
Animation
In Hierarchy select skeleton → skeleton and look at inspector.
A SkinnedMeshRenderer Component. SkinnedMeshRenderer, like MeshRendererer, is a subclass of Renderer. However, the SkinnedMeshRenderer Component renders the Mesh that wraps around the skeleton and follows its joints as they move. The Mesh essentially forms the skin around a skeleton, so the process of mapping such a Mesh to a skeleton is often called skinning.
In Hierarchy select skeleton
Change animation
Press play
Animation
Go to Assets → Skeleton Data → skeleton and look at inspector.
Select Animation
Select run in clips
Choose Wrap Mode → loop
run
Animation
Select Edit → Project Settings → Quality.
Quality settings features can be edited. Click on ? at top right of Inspector for detail.
Sound
Get Free music pack from asset store.
Select Monster Screens and drag from Assets → Free Pack → Monster screams to Hierarchy
Set Parameters in inspector
Play
Physics
Add an alley 5x1x5
Get 18 FREE Substances from Asset Store
Add wood and wood normals, bumped specular, increase size to 10x1x50 and tiling to 5,5,5,5
Add physic materials
Add sphere
Rigid bodies
Physics
Physics constants
Add materials and rigid body to sphere.
FixedUpdate
Look at TimeManager
Physics
Add script rollvar mousepowerx:float = 1.0;
var mousepowery:float = 1.0;
var maxvelocity:float=400.0;
private var forcey:float=0.0;
private var forcex:float=0.0;
private var isRolling:boolean=false;
private var floorTag:String = "alley";
var maxVelocitySquared:float=400.0;
Physics
Add script roll (continued)function Update() {
forcex = mousepowerx*Input.GetAxis("Mouse X")/Time.deltaTime;
forcey = mousepowery*Input.GetAxis("Mouse Y")/Time.deltaTime;
}
function FixedUpdate() {
if (isRolling && rigidbody.velocity.sqrMagnitude<maxVelocitySquared) {
rigidbody.AddForce(forcex,0,forcey);
} }
function OnCollisionEnter(collider:Collision) {
if (collider.gameObject.tag == floorTag) {
isRolling = true;
} }
Physics
Add script roll (continued)function OnCollisionStay(collider:Collision) {
if (collider.gameObject.tag == floorTag) {
isRolling = true;
} }
function OnCollisionExit(collider:Collision) {
if (collider.gameObject.tag == floorTag) {
isRolling = false;
} }
Physics
Add smooth follow to camera.
Assignment
Complete the tutorials at
http://unity3d.com/learn/tutorials/modules/beginner/physics
Physics
Colliders
Mesh Collider
Physics overview
Physics
Messages
Messages
BroadcastMessage
object send message
Animation
Use lateupate after animation update
Animation events
Animation Scripting
Character Controller
Text Book Chapter 8:FSM
Finite State Machines: Introduction
Finite State Machines
Finite State Machine Tutorial
State Diagrams
UML State Machine
28
Unity GUI System
Many game GUI's are graphic objects with a callback function attached to mouse/keyboard events realized on the object. The graphics and callbacks are setup during initialization. The code to initialize an object is general complex. As the callbacks are static, they become quite complex if the object is used frequently in different contexts.
The is called retained mode GUI
29
Unity GUI System
GUI Scripting Guide
Example Code
New Gui System
Game Programming
Misc
Setting Action Keys
Edit → Project Settings → Input → Axes
Editing Curves
Export/Import Assets.
DirectX settings
Edit → Project → Player Settings → Other
Math.lerp
IK (inverse kinematics)
Body Mask
Animation Rigging
Import Animation
Select Skeleton Data in Assets.
Select skeleton.
Select Rig.
Select Humanoid/Create from Model.
Configure
Mapping → automap
Muscles
Done
Animation Controller
An example of visual programming like OpenDX
Sets up finite state machine states
Defines transitions as unidirectional links
Actions defined in controller script
Animation Controller
Mecanim Tutorial starting at 17.03
Add animation 69_15 and 69_16 to Huge Mocap Library demo controler
Blend tree can be used to switch between animations
Assignment 3
Reimplement Assignment 2, but use an animation to turn the skeleton in place. The run and turn animations should be blended together. Several different animations may be required depending on the direction the avator is facing.