SE 320 – Introduction to Game Development Lecture 7: Programming Lecturer: Gazihan Alankuş Please look at the last two slides for assignments (marked with.

Slides:



Advertisements
Similar presentations
Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
Advertisements

SE 320 – Introduction to Game Development Lecture 5: Programming in Unity & Developing Simple Games Lecturer: Gazihan Alankuş Please look at the last two.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
UFCFSU-30-13D Technologies for the Web Creating and Updating a Graphical Heads-Up Display (HUD)
INNER WORKINGS OF UNITY 3D. WHAT WE ARE GOING TO COVER Intro to Unity Physics & Game Objects Cameras & Lighting Textures & Materials Quaternions and Rotation.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
SE 313 – Computer Graphics Lecture 14: Armatures Lecturer: Gazihan Alankuş 1.
UFCFSU-30-13D Technologies for the Web Creating and Using GUI Components.
The Concepts of Orientation/Rotation ‘Transformations’ ME Lecture Series 2 Fall 2011, Dr. R. Lindeke 1.
GameCamp! and Game Davis Creating a 2D Platformer in Unity.
GameCamp! and Game Davis Introduction to Scripting in Unity®
“Working with Fractions” A Review of Addition and Subtraction CLICK HERE TO BEGIN.
Physics 151 Week 11 Day 2 Topics: Forces, Apparent Weight, & Friction  Energy  Dot Produce  Work  Conservation of Energy with Work  Work-Energy Theorem.
10/5/04© University of Wisconsin, CS559 Fall 2004 Last Time Compositing Painterly Rendering Intro to 3D Graphics Homework 3 due Oct 12 in class.
SE 320 – Introduction to Game Development Lecture 11: Animations and GoKit Lecturer: Gazihan Alankuş Please look at the last slides for assignments (marked.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Physically Based Animation and Modeling
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
SE 313 – Computer Graphics Lecture 3: Analytical Geometry and Linear Algebra Lecturer: Gazihan Alankuş Please look at the last three slides for assignments.
SE 320 – Introduction to Game Development Lecture 4: Programming in Unity & Project Presentations Lecturer: Gazihan Alankuş Please look at the last two.
SE 350 – Programming Games Lecture 6: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
SE 350 – Programming Games Lecture 1: Introduction Lecturer: Gazihan Alankuş Please look at the last two slides for assignments (marked with TODO) 2/10/20121.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş Please look at the last two slides.
SE 350 – Programming Games Lecture 7: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
Description, Classes, Interfaces, Hierarchy, Specifics George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Web Games Programming An Introduction to Unity 3D.
Web Games Programming Unity Scripting Fundamentals.
UFCFS D Technologies for the Web Unity 3D: Review of Topics and Related Concepts.
SE 313 – Computer Graphics Lecture 6: Transformations Lecturer: Gazihan Alankuş Please look at the last three slides for assignments (marked with TODO)
Learning Unity. Getting Unity
Matthew Christian. About Me Introduction to Linear Algebra Vectors Matrices Quaternions Links.
SE 320 – Introduction to Game Development Lecture 3: Unity’s Interface and Concepts Lecturer: Gazihan Alankuş Please look at the last two slides for assignments.
SE 313 – Computer Graphics Lecture 8: Transformations and Projections Lecturer: Gazihan Alankuş 1.
XP Tutorial 8 Adding Interactivity with ActionScript.
UFCEK-20-3Web Games Programming Unity 3D: Review of Topics Publishing for the Web.
Unity GUI Creating and Using GUI Components. Agenda GUI Components GUI Layout Using Styles and Skins for Design ‘Look and Feel’ Scripting GUI Communication.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
SE 320 – Introduction to Game Development Lecture 2: Introduction to Unity Lecturer: Gazihan Alankuş Please look at the last two slides for assignments.
CLASSES CHAPTER Topics  Understanding Classes –The Anatomy of a Class  Class Inheritance –Superclasses and Subclasses –Virtual and Override 2.
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
SE 350 – Programming Games Lecture 5: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
UFCEKU-20-3Web Games Programming Instantiating World Objects.
UFCFSU-30-13D Technologies for the Web An Introduction to Unity 3D.
Expressive Intelligence Studio // Center for Games and Playable Media // Unity Pro John Murray Expressive.
 How can we find/refer to objects at runtime?  This must be dynamic because objects may come and go.  How can we solve this problem?
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Behavior trees & The C# programming language for Java programmers
EEC-693/793 Applied Computer Vision with Depth Cameras
Quick Intro to Unity Lecture 2.
First Person Shooter Project
More (C#) Scripting Day 2, Lesson 1.
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
One-Dimensional Array Introduction Lesson xx
Oculus Rift DK2 + Leap Motion Unity Tutorial
Game Loop Update & Draw.
ROOM 2+ FEATURES A-CREEPIN’ BEFORE WE START: LANYARDS RECAP ALL HERE?
Week 6: Time and triggers!
Myo + Oculus Rift Tutorial
Fundaments of Game Design
EEC-693/793 Applied Computer Vision with Depth Cameras
Unity Game Development
Unity Game Development
Presentation transcript:

SE 320 – Introduction to Game Development Lecture 7: Programming Lecturer: Gazihan Alankuş Please look at the last two slides for assignments (marked with TODO) 1

Sample Games in Homework URL was: examples/1sGhttp://u3d.as/content/m2h/c-game- examples/1sG What were the things that you found interesting? What have you learned? What were your issues? – Let’s quickly go over the games – Jump in when we are close to your question! 2

How does a game work? You write code – that is able to manipulate the game world That code is ran – at certain points in time You manipulate game state 3

Game State Examples – HP (life) – Ammo – Inventory items – Cool-down time for a skill – Experience More examples from actual games 4

Implementing State Variables in your custom components public class LifeManager : MonoBehaviour { public float HP; } The instance of the component will reflect state of the game object that it is attached to. – Different instances of your prefab will have different values for the state variables 5

Implementing State Locality of state – which component should keep which state? – One component that keeps HPs of all characters in the game? – Every character keeps his own HP? 6

Accessing Objects in the Scene Getting another game object – GameObject enemy = GameObject.Find(“enemy”); //or the one below – public GameObject enemy; //drag to this Getting a component – Attached to the same game object MyComponent c = GetComponent (); – Attached to some other game object MyComponent c = enemy.GetComponent (); Using parent/child relationships – Transform parentsTransform = transform.parent; – GameObject parent = transform.parent.gameObject; 2/10/20127

Accessing Objects in the Scene It’s slow to keep calling GameObject.Find(“..”) Make connections in the Awake function public class Player: MonoBehaviour { GameObject enemy; void Awake() { enemy = GameObject.Find("enemy"); } 8

Data Types in Unity Some standard data types – Vector3 (position, direction, displacement) – Quaternion (orientation, rotation) Details of standard components – Transform, Collider, Renderer, RigidBody Basic data structures in C# – List, Dictionary, etc. 2/10/20129

Vector3 Vector3 means “three dimensional vector” Just three floats: x, y and z Often used for talking about a 3D position or direction – Contains methods/properties that help in this domain e.g., transform.position is a Vector3 2/10/201210

Vector3: related to magnitude v.normalized v.magnitude v.Normalize 2/10/201211

Vector3: some constants Vector3.zero == new Vector3(0, 0, 0) Vector3.one == new Vector3(1, 1, 1) (LOL) Vector3.forward == new Vector3(0, 0, 1) Vector3.back == new Vector3(0, 0, -1) Vector3.up == new Vector3(0, 1, 0) Vector3.down == new Vector3(0, -1, 0) Vector3.right == new Vector3(1, 0, 0) Vector3.left == new Vector3(-1, 0, 0) 2/10/201212

Vector3: Averaging (interpolating) Vector3.Lerp(v1, v2, fraction) Vector3.Slerp(v1, v2, fraction) 2/10/ v1v2 0fraction1 v1v2 0 fraction 1 origin (0, 0, 0)

Vector3: Geometric operations Vector3.Scale(v, s) Vector3.Project(v, vbase) Vector3.Angle(v1, v2) Vector3.Distance(v1, v2) Vector3.Dot(v1, v2) Vector3.Cross(v1, v2) 2/10/201214

Vector3: operators v1 + v2 – Adds x, y, z values separately and returns the sum vector 3.5 * v – Multiplies x, y, z with 3.5 2/10/201215

Quaternion Has four values (x, y, z, w). What are they? – Don’t worry about its mathematical definition (has four values, etc. don’t care because they won’t make sense in our context) Is simply (both of these below are true) – A vector and an angle Rotate around that vector with that angle – Three consecutive rotations around z, x and y axes Represents – Orientation (rotate to here from default orientation) – Rotation (change in orientation) 2/10/201216

Quaternion q.x, q.y, q.z, q.w – DON”T CARE!!!1!!! – NEVER USE THEM!!!!! 2/10/201217

Quaternion: its value that makes sense q.eulerAngles – Vector3 that contains rotations around axes – Rotation order is z, x, y (but you don’t have to care) q.ToAngleAxis(out angle, out axis) – sets the angle and axis variables that you give to it – rotation around that axis with that angle amount 2/10/201218

Quaternion: operations q1 * q2 – the result is the rotation that is equal to: rotate with q2 first, and then with q1 – or, if q2 is orientation of something, rotates it with q1 (same thing, slightly different interpretation) q * v – rotate v with q Quaternion.Dot(q1, q2) Quaternion.AngleAxis(angle, axis) Quaternion.Euler(x, y, z) Quaternion.Inverse(q)... 2/10/201219

Quaternions: Averaging (interpolating) Quaternion.Slerp(q1, q2, fraction) – The correct way to interpolate two quaternions Quaternion.Lerp(q1, q2, fraction) – Slightly faster, bad interpolation (moves faster in the middle) 2/10/201220

There are more Ray, Rect, Vector2, Vector4, etc. Use the scripting reference 2/10/201221

Standard components Have – Properties (variables) Can’t modify Can set for an instance – Functions Can call for an instance – Class functions (static) Can call with the class name, without an instance – Messages Functions are called on all components that are attached to the GameObject when events happen (via SendMessage) 2/10/201222

Transform transform.position transform.rotation – With respect to the world. Changes when parent changes. – Not what you see in the inspector. transform.localPosition transform.localRotation transform.localScale – With respect to the parent. Does not change when parent changes. – What you see in the inspector transform.right, transform.up, transform.forward – x, y, z axes of the orientation (the arrows you see) 2/10/201223

Global vs. Local 2/10/ p c p.position == p.localPosition c.localPosition c.position c.transform.parent == p.transform

Global vs. Local 2/10/ p c p.position == p.localPosition c.localPosition c.position Red ones changed as a result of moving the parent All of this is the same for rotation and localRotation

Renderer r.material r.isVisible 2/10/201226

Colliders c.isTrigger – True Not used in physics calculations, lets things through OnTriggerEnter is sent to the GameObject (and its components) – False Used in physics calculations, won’t let things through OnCollisionEnter is sent to the GameObject (and its components) 2/10/201227

Colliders c.material – The physics material (PhysicMaterial) friction constants bounciness 2/10/201228

Standard components Have – Properties (variables) Can’t modify Can set for instance – Functions Can call for instance – Class functions/class variables (static) Can use with class name, without an instance. Like global variables but in class. – Messages Functions are called on all components that are attached to the GameObject when events happen Examples – t.position = t.position + Vector3.up; – t.Translate(1, 1, 1) – Vector3.Lerp(v1, v2, f) – Vector3.up – Update() – OnCollisionEnter() – OnCollisionEnter(Collision collision) 2/10/201229

There are many other components Use the scripting reference! 2/10/201230

Collection Data Structures in C# using System.Collections; using System.Collections.Generic; List enemies = new List (); – loop with foreach, access enemies[5] Dictionary enemiesByName = new Dictionary (); – access by enemy name. enemiesByName[“wolf”] – loop with foreach Amazing resource: Also should watch: Fundamentals-Development-for-Absolute-Beginners/Working-with- Collections-21http://channel9.msdn.com/Series/C-Sharp- Fundamentals-Development-for-Absolute-Beginners/Working-with- Collections-21 31

Game Structure You will have GameObjects for various elements in your game (character, enemy, robot, etc). Create their own scripts and put code specific for them. You also need to have code that is common for the game (scoring is an example). Attach such scripts on the camera or on a similarly unique object. Wire them up in Awake() For common singletons, create – static MyScript instance; – public static MyScript getInstance() { return instance; } – public MyScript() { instance = this; } And in other scripts, – MyScript myScript = MyScript.getInstance(); – Easier than GameObject.Find() 2/10/201232

TODO: Homework Start with your own Homework 3 (ask the assistant if you haven’t done it) Add a bullet prefab that you will use to make your character throw bullets You already should have a monster prefab. Add a 3D text over its head that you will use to display the monster’s remaining life percentage. Create a MonsterLifeManager component that will handle changing and displaying life of the monster that it’s attached to. Make it so that the space key will throw a bullet towards which your character is facing (transform.forward). The bullet needs to remember this initial direction and should move proportional to time at each frame (update) towards this direction. When a bullet hits a monster, it should reduce its life by a random value between 5 and 10. Initially life is 100. When life gets to zero, the monster disappears. You should have at least three monsters in the scene Bonus: reduce monster’s life depending on the body part that is hit (headshot, etc.) Get Özkan to grade it – – Subject (paste this): SE 320 Homework 7 – What to send: Assets -> Export package File -> Build Settings -> Web player -> Build 33