Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

GA4403

Intermediate Scripting Languages
by

Glenn Lewis

on 10 November 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of GA4403

GA4403
Intermediate
Scripting Languages
week 1
http://prezi.com/i96x7clrgkwf
Instructor: Glenn Lewis
e-mail: gmlewis@aii.edu
Right now, please send me an e-mail
with the following information:
Your name
Your Student ID
Your major or focus
Any programming experience you may have
Any 3D application experience you may have
Your favorite game genre (FPS, MMO, RPG, etc.)
Your favorite game (and on what platform)
Your favorite platform
What you would like to get out of this class
Anything else you think I should know
(cover syllabus)
Some popular scripting languages
Python
Lua
ZScript
ActionScript
MEL
MAXScript
JavaScript
Groovy
Scala
Perl
Ruby
Processing
Unreal Script
Maya
Blender
Maya
Google App Engine
UDK
3ds Max
ZBrush
Sketchup
web browsers
Flash
Tcl/Tk
Great for:
quick experiments
prototyping
applications
extensions
websites
game logic and customization
What features do most
scripting languages have
in common?

Why are they important?

What are they used for?
Python Review
Sudoku Solver Review
ActionScript Exercise
Homework Assignment #1
Take the Flash ActionScript example worked on in class
and add a new object that flies across the screen
horizontally but randomly switches its vertical motion
causing a zig-zag pattern as it goes across.
Worth: 100 points
E-mail solution (.FLA, .AS, and .SWF) to
gmlewis@aii.edu before class time on Week 4
Flash and ActionScript
lots of interest still
work through game example
together in class
Researching Game Engines
UDK: udk.com
Unity: unity3d.com
Two Game Projects
in tandem

1. In-class game

2. Final project
Wheel of Fortune -like game
3D using Unity Engine
Artwork and animations provided by students
Scripting provided by entire class working together
This collaboration will give students a feel for working with a
team on a non-trivial project where the scripting drives the game action.

Needed assets/animations:
game set (letters, wheel to spin, contestant stands, platform, etc.)
"Vanna" - letter-turner with corresponding animations
"Player" - reaching over and spinning wheel, excitement, disappointment, etc.
"Robot1" - similar animations, different body
"Robot2" - ditto
"Pat" - show host (lower priority)
voice-overs - entire alphabet in 4 different voices (Vanna is silent)
"I would like to buy a vowel...", "Give me a...", "Is there a...", "Woohoo!", etc.
"There is one...", "There are...", 2, 3, 4, 5, etc.
"Would you like to spin?", "Give it a spin", "Our topic is...", etc.
sound effects (wheel spinning, bankrupt sound, new topic, etc.)
Final Project
Students will form groups of 2 or 3 people
You are to create a simple 2D or 3D game using one
of the following technologies:
ActionScript (Flash)
UnityScript (JavaScript, C# or Boo)
UnrealScript (UDK)
Choose a game and come up with a proposal.
Emphasis should be placed on scripting which will
be the focus of the grading.
Examples:
80's arcade games (pac-man, donkey kong, etc.)
TV game shows (jeopardy, deal no-deal, etc.)
board games (sorry, mastermind, wizard chess, etc.)
week 2
Make Centipede Playable
Quiz #1 - ActionScript
"closed book" quiz
no internet
no computers
no assistance from neighbors

Worth: 100 points
Final Project Proposals
E-mail the following information to gmlewis@aii.edu:
1. Names of the 2 or 3 people in your group
2. The name of your Final Project
3. Description of your Final Project
4. Describe how you will present your project
to the class, remembering that each member
must participate and be able to answer
questions about the project
week 3
Introduction to the
Unity Game Engine
http://www.unity3d.com/
week 4
Let's Spin that Wheel!
1. File / New Project - WheelOfFortune
in project wizard, create new project, include
Standard Assets.unityPackage
Create Package

Notes: We want the following objects:
the set, 3 stands, the wheel, 12/14/14/12 letters, 3 players,

2. We'll create the set's ground first...
GameObject / Create Other / Plane
Hit F2 to rename it... call it Floor
Change X,Y,Z scales to 100 (meters)
Change X,Y,Z positions to 0 (origin)
(take a look - pretty boring - flat plane)
3. Want to make a nice background...
Select Main Camera
Component / Rendering / Skybox
new component in inspector
open up Project / Skyboxes
drag Sunset over to "Skybox / Custom Skybox / None (Material)"

4. GameObject / Create Other / Plane
Position: 0, 1, 0
Scale: 0.5, 0.5, 0.5
Rename to Wheel
5. Import texture for wheel
Asset / Import New Asset ...
500px-Wheel_of_Fortune_-_Season_26_-_Round_4.svg.png
Under Project, click on: Create Material
Rename the material WheelMaterial
While WheelMaterial is selected, drag the PNG to the selector in the Inspector
(or just click Select and choose the PNG)
Now drag & drop the WheelMaterial onto the Wheel

6. We need to make the edges transparent where the PNG is transparent
Click on the Wheel
Under the Inspector, change the WheelMaterial Shader type to:
Transparent / Cutout / Diffuse
7. Now we want to see it spinning... click on Play - can't see the wheel
Select the Main Camera
Change position to: 0 2 -5

8. Improve the looks a little bit...
Chane the Scale of the Wheel to 0.5, 0.5, 0.5
Drag the Cliff (Layered Rock) texture (from Project / Terrain Textures)
to the Floor and change Tiling to 10, 10
9. Under Project, click on Create / JavaScript
Rename to RotateWheel
Edit script...
function Update() {
transform.rotation.y += Time.deltaTime;
}
Play - doesn't yet rotate
Drag RotateWheel to Wheel
Play - rotates - but slows down and stops

10. Constant rotation:
transform.Rotate(0,5,0); // doesn't account for frame rate...
pretty fast rotation
// constant speed no matter what the frame rate
transform.Rotate(0,5*Time.deltaTime,0);
try...
transform.Rotate(0,50*Time.deltaTime,0);
11. Save scene as "GameSet.unity" (under the default Assets)

12. We want realistic rotation...
Click on Component / Physics / Rigidbody
trying playing it... we need to turn off Gravity
Change the script:
function FixedUpdate () {
rigidbody.AddTorque (Vector3.up * 10);
}
and comment out all the Start and Update tests...
Play and see it constantly spinning...
13. Move the AddTorque to the Start method... test... too slow, and not enough drag
Change the 10 to 100...
Change the Angular Drag from 0.05 to 0.5... still not enough... change to 1
Still not enough force... change to 1000

14. Changed mechanism... set angular drag to 0.9
var impulseTime : float = 1.0;

private var startTime : float = 0.0;

function Start() {
startTime = Time.time;
}

function Update () {
if (Time.time - startTime <= impulseTime) {
Debug.Log("AddTorque...");
rigidbody.AddTorque (Vector3.up * 100);
}
}
15. Add a function "spinWheel()" that starts the process...
Add another function "wheelStopped()" that detects when it stops...

16. Work on script...
//////////////////////////////////////////////////////////////////////
static var impulseTime : float = 1.0;
static var startTime : float = 0.0;
static var wheelSpinning : boolean = false;

private var numSpaces : int = 24;
private var spaces : Array;

function Start() {
spinWheel(1.0);
// Set up the spaces array
spaces = [5000, 600, 500, 300, 500, 800, 550, 400, 300, 900, 500, 300, 900, "Bankrupt",
600, 400, 300, "Lose A Turn", 800, 350, 450, 700, 300, 600];
}

function Update () {
if (wheelSpinning) {
if (Time.time - startTime <= impulseTime) {
// Debug.Log("AddTorque...");
rigidbody.AddTorque (Vector3.up * 100);
} else {
// Check to see if the wheel stopped spinning
// Debug.Log("rigidbody.angularVelocity.magnitude="+rigidbody.angularVelocity.magnitude);
if (rigidbody.angularVelocity.magnitude == 0) {
wheelStopped();
}
}
}
}

function FixedUpdate () {
}

static function spinWheel(impulseTime : float) {
RotateWheel.startTime = Time.time;
RotateWheel.wheelSpinning = true;
RotateWheel.impulseTime = impulseTime;
}

function wheelStopped() {
RotateWheel.wheelSpinning = false;
// Figure out what angle it ended up at... print it, then spin again...
// Debug.Log("Wheel stopped at: rigidbody.rotation.eulerAngles="+rigidbody.rotation.eulerAngles);
rotAngle = rigidbody.rotation.eulerAngles.y;
space = spaces[Mathf.FloorToInt(rotAngle / numSpaces)];
Debug.Log("Wheel stopped at y="+rotAngle+" degrees. Space="+space);

// Spin the wheel again...
spinWheel(1.0);
}

//////////////////////////////////////////////////////////////////////
17. Move camera to above wheel to calibrate the settings... need a marker for spinner
Select Main Camera
Set position to 0, 6, 0
Set rotation to 90, 0, 0
Select GameObject / Align View to Selected, in order to look from camera
Now manually set Wheel to different Y rotations and check algorithm... (and set it back to 0)
360 / 24 = 15 degress - so every 15 degrees we have a new number...

//////////////////////////////////////////////////////////////////////
static var impulseTime : float = 1.0;
static var startTime : float = 0.0;
static var wheelSpinning : boolean = false;

private var numSpaces : int = 24;
private var spaces : Array;

function Start() {
spinWheel(3.5);
// Set up the spaces array
spaces = [5000, 600, 500, 300, 500, 800, 550, 400, 300, 900, 500, 300, 900, "Bankrupt",
600, 400, 300, "Lose A Turn", 800, 350, 450, 700, 300, 600];
}

function Update () {
if (wheelSpinning) {
if (Time.time - startTime <= impulseTime) {
// Debug.Log("AddTorque: Time.time="+Time.time+", startTime="+startTime+", impulseTime="+impulseTime);
rigidbody.AddTorque (Vector3.up * 100);
} else {
// Check to see if the wheel stopped spinning
// Debug.Log("rigidbody.angularVelocity.magnitude="+rigidbody.angularVelocity.magnitude);
if (rigidbody.angularVelocity.magnitude == 0) {
wheelStopped();
}
}
}
}

function FixedUpdate () {
}

static function spinWheel(newTime : float) {
startTime = Time.time;
wheelSpinning = true;
impulseTime = newTime;
}

function wheelStopped() {
wheelSpinning = false;
// Figure out what angle it ended up at... print it, then spin again...
// Debug.Log("Wheel stopped at: rigidbody.rotation.eulerAngles="+rigidbody.rotation.eulerAngles);
rotAngle = rigidbody.rotation.eulerAngles.y;
myIndex = Mathf.FloorToInt(0.5 + ((360.0-rotAngle) * numSpaces / 360));
if (myIndex < 0) { myIndex = spaces.length-1; } // wrap around
else if (myIndex >= spaces.length) { myIndex = 0; }
space = spaces[myIndex];
Debug.Log("Wheel stopped at y="+rotAngle+" degrees. myIndex="+myIndex+", Space="+space);

// Spin the wheel again...
spinWheel(3.5);
}

//////////////////////////////////////////////////////////////////////
18. Add spotlight to scene to see wheel
GameObject / Create Other / Spotlight
Position: 0, 14, 0
Rotation: 90, 0, 0
Intensity: 1
Range: 20

19. Make the motion a bit more realistic...
The only thing that changes is the person's strength...
They each have about 1 second to spin up the wheel. So...

First, fixed the private variable problem from a static function...
//////////////////////////////////////////////////////////////////////
static var wheelSpinning : boolean = false;

private var numSpaces : int = 24;
private var spaces : Array;
private var impulseTime : float = 1.0;

private var startTime : float = 0.0;
private var personStrength : float = 100.0;

function Start() {
spinWheel(personStrength);
// Set up the spaces array
spaces = [5000, 600, 500, 300, 500, 800, 550, 400, 300, 900, 500, 300, 900, "Bankrupt",
600, 400, 300, "Lose A Turn", 800, 350, 450, 700, 300, 600];
}

function Update () {
if (wheelSpinning) {
if (Time.time - startTime <= impulseTime) {
// Debug.Log("AddTorque: Time.time="+Time.time+", startTime="+startTime+", impulseTime="+impulseTime);
rigidbody.AddTorque (Vector3.up * ((Time.time - startTime) * personStrength / impulseTime));
} else {
// Check to see if the wheel stopped spinning
// Debug.Log("rigidbody.angularVelocity.magnitude="+rigidbody.angularVelocity.magnitude);
if (rigidbody.angularVelocity.magnitude == 0) {
wheelStopped();
}
}
}
}

function FixedUpdate () {
}

static function spinWheel(newStrength : float) {
var comp = GameObject.Find("Wheel").GetComponent(RotateWheel);
comp.startTime = Time.time;
comp.personStrength = newStrength;
wheelSpinning = true;
}

function wheelStopped() {
wheelSpinning = false;
// Figure out what angle it ended up at... print it, then spin again...
// Debug.Log("Wheel stopped at: rigidbody.rotation.eulerAngles="+rigidbody.rotation.eulerAngles);
rotAngle = rigidbody.rotation.eulerAngles.y;
myIndex = Mathf.FloorToInt(0.5 + ((360.0-rotAngle) * numSpaces / 360));
if (myIndex < 0) { myIndex = spaces.length-1; } // wrap around
else if (myIndex >= spaces.length) { myIndex = 0; }
space = spaces[myIndex];
Debug.Log("Wheel stopped at y="+rotAngle+" degrees. myIndex="+myIndex+", Space="+space);

// Spin the wheel again...
spinWheel(personStrength);
}
//////////////////////////////////////////////////////////////////////
20. Now to 'loosen' up the wheel...
static var wheelSpinning : boolean = false;

private var numSpaces : int = 24;
private var spaces : Array;
private var impulseTime : float = 1.0;

private var startTime : float = 0.0;
private var personStrength : float = 100.0;

function Start() {
spinWheel(personStrength);
// Set up the spaces array
spaces = [5000, 600, 500, 300, 500, 800, 550, 400, 300, 900, 500, 300, 900, "Bankrupt",
600, 400, 300, "Lose A Turn", 800, 350, 450, 700, 300, 600];
}

function Update () {
if (wheelSpinning) {
if (Time.time - startTime <= impulseTime) {
// Debug.Log("AddTorque: Time.time="+Time.time+", startTime="+startTime+", impulseTime="+impulseTime);
rigidbody.AddTorque (Vector3.up * ((Time.time - startTime) * personStrength / impulseTime));
rigidbody.angularDrag = 0.01;
} else {
// Check to see if the wheel stopped spinning
// Debug.Log("rigidbody.angularVelocity.magnitude="+rigidbody.angularVelocity.magnitude);
if (rigidbody.angularVelocity.magnitude == 0) {
wheelStopped();
} else {
newDrag = (Time.time - startTime - 2*impulseTime) / 10.0;
if (newDrag < 0.01) newDrag = 0.01;
if (newDrag > 1.0) newDrag = 1.0;
// Debug.Log("Setting angularDrag to: "+newDrag+" at time "+Time.time);
rigidbody.angularDrag = newDrag;
}
}
}
}

function FixedUpdate () {
}

static function spinWheel(newStrength : float) {
var comp = GameObject.Find("Wheel").GetComponent(RotateWheel);
comp.startTime = Time.time;
comp.personStrength = newStrength;
wheelSpinning = true;
}

function wheelStopped() {
wheelSpinning = false;
// Figure out what angle it ended up at... print it, then spin again...
// Debug.Log("Wheel stopped at: rigidbody.rotation.eulerAngles="+rigidbody.rotation.eulerAngles);
rotAngle = rigidbody.rotation.eulerAngles.y;
myIndex = Mathf.FloorToInt(0.5 + ((360.0-rotAngle) * numSpaces / 360));
if (myIndex < 0) { myIndex = spaces.length-1; } // wrap around
else if (myIndex >= spaces.length) { myIndex = 0; }
space = spaces[myIndex];
Debug.Log("Wheel stopped at y="+rotAngle+" degrees. myIndex="+myIndex+", Space="+space);

// Spin the wheel again...
spinWheel(personStrength);
}

//////////////////////////////////////////////////////////////////////
21. Attempt to add pegs to wheel
If I manually add a peg, it works fine...
Position: 2.49, 1, 0
Scale: 0.1, 0.5, 0.1
But if I add it like this:

function Start() {
// Set up the spaces array
spaces = [5000, 600, 500, 300, 500, 800, 550, 400, 300, 900, 500, 300, 900, "Bankrupt",
600, 400, 300, "Lose A Turn", 800, 350, 450, 700, 300, 600];

var comp = GameObject.Find("Wheel");

// Create the pegs around the cylinder
var pegs : Array = [ ];
for (i=0; i < spaces.length; i++) {
var cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
var rad : float = 2.49;
var ang : float = (i + 0.5) * 360.0 / spaces.length;
var newx : float = rad * Mathf.Cos(ang * Mathf.Deg2Rad);
var newz : float = rad * Mathf.Sin(ang * Mathf.Deg2Rad);
Debug.Log("Creating cylinder at: angle="+ang+", ("+newx+", 1, "+newz+")");
cylinder.transform.localPosition = Vector3(newx, 1, newz);
cylinder.transform.localScale = Vector3(0.1, 0.5, 0.1);
cylinder.transform.parent = comp.transform;
pegs[i] = cylinder;
}

spinWheel(personStrength);
}

Then the physics get all messed up.
Posted a message to:
http://answers.unity3d.com/questions/8836/
dynamic-scripted-vs-static-modeled-parenting-physics-behaves-differently
http://usa.autodesk.com/adsk/servlet/index?id=13956066&siteID=123112&linkID=10223692
http://www.hometot.com/unity/wheel_works.html
http://www.apple.com/hotnews/thoughts-on-flash/
Homework Assignment #2
Worth: 100 Points
DUE: Before class next week
Please do NOT wait until the morning of class to start it!
Using Unity3D, create a new project with the following:
a plane for the floor
choose one of: sphere, cylinder, or cube
place it in the scene
put a texture on it and a spotlight on it
point the MainCamera at it
using JavaScript, constantly rotate the object
(Remember to save your Scene as well as your Project!!!)
ZIP up your project directory and copy to the Faculty drive
under "glewis/GA4403". Please send me an e-mail when it is
completed to: gmlewis@aii.edu
GA4403 Midterm Exam
"Closed book" except for your class notes
no internet searches
no web browsers
no e-mail access during exam
no online or local help files from Flash or Unity
you may look at any code you have written in class
no help from neighbors
give each question your best shot - don't leave items blank
please write your name at the top of each page
Making the Puzzle Board
create the board pieces

add some iTween animation and test it out

add TextMesh letters to the board pieces
var textMeshPrefab : TextMesh;

static var numLines : int = 4;
static var lines : Array = [ "", "", "", "" ];
static var lineLength : Array = [ 12, 14, 14, 12 ];
static var boxes : Array;

static var xpos : int = 0;
static var zpos : int = 20;
static var xspacing : int = 2;
static var yspacing : int = 2;

function Start () {
boxes = [ ];
for (line=0; line < numLines; line++) {
boxes[line] = new Array();
boxes[line].length = lineLength[line];
for (letter=0; letter < lineLength[line]; letter++) {
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
boxes[line][letter] = cube;
cube.transform.position = Vector3(xpos + (letter -
lineLength[line]/2)*xspacing, (numLines-line)*yspacing, zpos);

iTween.rotateTo(cube,{"y":90, "time":2, "delay":(line*14+letter)});

// Add a texture to the cube
var textMesh = Instantiate(textMeshPrefab, Vector3.up*10,
Quaternion.identity);
textMesh.text = "Z";
cube.renderer.material.color = Color(1,1,1,1);
textMesh.transform.parent = cube.transform;
textMesh.transform.localPosition = Vector3(0,0,0);
textMesh.transform.localEulerAngles = Vector3(0,-90,0);
}
}
}
// iterate over each line of the puzzle board
// iterate over each letter of each line
// create the cube
// save a reference to the cube for future access
// test out the rotation animation of the cube
// has some problems with opacity still
week 6
Finite State Machines
When designing games, it is often necessary
to keep track of the state of not only the
game as a whole, but individual objects themselves.

For example, a rocket is launched and stays in the
"flying" state until it collides with an object, then
is "exploding" and finally "dies" and is removed from
the games.

A Finite State Machine (FSM) is a simple way to keep
track of the states and transitions of an object.
A finite state machine (FSM) or finite state automaton (plural: automata), or simply a state machine, is a model of behavior composed of a finite number of states, transitions between those states, and actions. It is similar to a "flow graph" where we can inspect the way in which the logic runs when certain conditions are met. A finite state machine is an abstract model of a machine with a primitive (sometimes read-only) internal memory.
Wikipedia definition of FSM
http://en.wikipedia.org/wiki/Finite_State_Machine
start
correct1
correct2
solved
incorrect
turn flame on
turn flame off
week 7
week 8
week 9
week 10
week 1
week 2
week 3
week 4
week 5
week 6
week 7
week 8
week 9
week 10
Homework Assignment #3
Rube Goldberg Machine
Worth 200 points
Due before class Week 7
Start Early! Expect to spend about 4 hours on this one.
Create a completely NEW PROJECT in Unity
Come up with a Finite State Machine with at least 5 unique states
Write your FSM in Unity JavaScript
At each state-change "print" the 'before' and 'after' states and
the event that caused the state change
Send an e-mail to gmlewis@aii.edu that describes steps required (if any)
to move your FSM through its states for testing the script
Try to ZIP up the ASSETS folder (not the Library folder) and
e-mail it to gmlewis@aii.edu... but if it is too big, place a ZIP of your
ENTIRE project into the Faculty / glewis / GA4403 directory
Your scene can be as simple or as complex as you wish - the grading
will focus solely on the CREATIVITY of your RGM and the SCRIPTING
of your FSM. (e.g. primitives are fine)
Events can be anything - user clicking, iTween "onComplete" callbacks,
"onCollisionEnter" callbacks, physics engine => translations or rotations, etc.
Think "Rube Goldberg Machines" (do a Google search)
Examples of FSMs
Simple Puzzle
Unity Game Development Essentials
Coconut Game
Note that there can be as many FSMs as needed.
Each object could have its own FSM.
FSMs could fire events that cause other FSMs to change states.
Simple FSM
http://store.steampowered.com/freeportal
www.youtube.com/watch?v=nCgQDjiotG0
answers.unity3d.com
Wheel of Fortune
Main Game Finite State Machine
Continuation of
Finite State Machines
- but first -
http://store.steampowered.com/app/50820/
http://www.rockpapershotgun.com/2009/09/08/unitys-nicholas-francis-on-making-tech-accessible/
Fix the Bugs Quiz #2
1. Copy the directory called "WOF_BugQuiz2" from
the faculty drive (glewis/GA4403/WOF_BugQuiz2)
to your desktop.
2. Fire up Unity and open the project
3. Each of the following 6 scripts has two bugs in it:
Board.js
Game.js
Player.js
PlayerChoicesGUI.js
PlayerLetterChoicesGUI.js
RotateWheel.js
4. Find and fix each bug so that the project behaves identically
to the example displayed in class.
5. Email me a ZIP of the 6 JavaScript files to gmlewis@aii.edu
Do *not* put your solution on the faculty drive
100 points
Review
Muddiest
Clearest
somewhere in between
Final Projects!
Everyone will fill out an evaluation for each of your peers.

You will be scoring each presenter using the following scale:
1= poor
2= needs improvement
3= satisfactory
4= very good
5= excellent

You will rate each presenter in these areas:
1) overall apparent contribution to project
2) participation in presenting project
3) ability to answer questions about project
Full transcript