Monday, December 13, 2010

Vector Math

I ran into a fun  problem while working on The Bridge today:



In my process of refactoring the ship engine, I added a rotational thruster to turn the ship. When the player issues a Turn Clockwise command, the Navigator AI will apply the rotational thruster to the ship until it reaches the desired velocity.

Here are the properties I worked with:
  • A target yaw, pitch, and roll to rotate to, in terms of angular velocity
  • Current angular velocity of the ship
  • Angular acceleration of the ship's engines

Each of these I represented as a Vector3 in XNA
  • Vector3 targetAngularVelocity;
  • Vector3 currentAngularVelocity;
  • ship.engines.angularThrust

I figured that the most logical way to approach this was to adjust angularThrust every frame in an Update loop. The challenge was figuring out what acceleration was appropriate, when only given currentAngularVelocity and targetAngularVelocity.

My first attempt involved finding a midpoint vector with a simple LERP:
ship.engines.angularThrust = Vector3.Lerp(currentAngularVelocity, targetAngularVelocity, strength) * time;
This works when going from not rotating at all, to rotating in some direction. However, it fails miserably if the ship is already moving in some capacity. I ended up spinning the player's ship phenomenally fast.



Clearly, a midpoint isn't good enough, I need something a bit more relative.

Thankfully, a simple Vector Math trick works nicely:
ship.engines.angularThrust = (targetAngularVelocity - currentAngularVelocity) * strength * time;
Subtracting targetAngularVelocity from currentAngularVelocity will give me a new Vector that points from currentAngularVelocity  to targetAngularVelocity . Then all I need to do is shrink the strength of the vector down to a reasonable acceleration, and I'm done.


And thanks to the miracles of Vector Math, this will work in any direction, under any circumstance. 


Sunday, November 07, 2010

Typical Day

I have a daily habit of scanning through kotaku.com and gizmodo.com. As I read through article headlines, I open the articles in new tabs for later reading. Here's a sample of what that looks like:


I find it a good way to keep up to speed with current trends in the game and gadget industries, and also find lots of cool pictures.

Sometimes I will watch a video as I read through web articles. Generally I'll watch at a TED conference or two since I find them pretty enriching. The window resizing features in Windows 7 are particularly useful here:



Have a favorite news website to procrastinate on? Leave a comment below.

Wednesday, October 27, 2010

The Bridge

This semester, I am the Technical Lead of a super-cool Science Fiction game called The Bridge.


In the game, you command starship entirely with voice control.

Here are some of the innovate things the game has going for it:

  • Speech Recognition as a seamless part of gameplay
    • The player can say things like:
      • "Weapons, fire missiles at enemy ship alpha"
      • "Navigator, engage defense orbit"
  • Dynamic Story Engine
    • Every actor in the game is an Entity
    • Entities have Relationships with other Entities
    • Relationships evolve throughout gameplay
    • Result: fully procedural storytelling
  • Emotional Voice Recognition
    • The player's tone is interpreted by the game
    • This affects crew loyalty towards the player



Of course, that's only the beginning.



For more information, check out the game's website:
commandthebridge.com



- Greg

Friday, September 17, 2010

Flash Sound Tutorial

I made a tutorial for using Sound Objects in Flash.





The tutorial covers a few tricks I use, including:
  • Object Dictionaries
  • Creating Asset Instances in the Flash IDE
  • Importing Sound Assets
  • Creating Sound Objects in ActionScript
  • Using Sound Objects
    • Play, Stop, and Change Volume
You can download the tutorial here:

The tutorial includes a Complete copy of the code, and a Skeleton copy for you to practice writing yourself. You will need Flash CS4 or later.



Surprisingly, creating a robust Sound Engine only requires about 60 lines of code.

Hope it's useful,
- Greg

Thursday, July 08, 2010

AStar Game

Recently, I learned how to implement the super-awesome pathfinding algorithm called A*. Given a start point and a goal, A* will find the shortest possible path to the goal while evaluating as few paths as necessary.

Not satisfied with leaving such a juicy algorithm to rot in a classroom, I set out to build a game.


I chose to create a Cat and Mouse game where the player tries to reach a goal while running away from evil baddies. Sound familiar? Well I've made it before:



Warp Chase was the first videogame I ever made. And by "made", I mean copy-pasted from a game programming book and added some levels. Oh shame. At the time, I did my best to add some personal spirit to the title, but didn't know enough concepts to program any of the gameplay that I had imagined.

Lucky for me, this kind of game lends itself perfectly to A*, since baddies need to be pretty movement-efficient to chase the player effectively. I set forth to fully realize the gameplay I couldn't quite grasp before.





Implementing A* was an interesting exercise in itself. I spent a few days experimenting and optimizing my implementation. Ultimately, I cut my processing time for a long A* search from 117 milliseconds to under 4. The biggest gains came from two places: First, I evaluated visited nodes by looking up values in a 2D array, rather than wastefully looking through each nodes list of visited previous nodes. Second, I implemented my own priority queue using a heap, which saved a lot of time on sorting.



From a gameplay standpoint,  the escape mechanic was fun for a while, but I quickly grew bored of it. A* was just too intelligent to waste on such shallow gameplay.

I wanted strategy.

While finishing the implementation for the Escape part of the game, I stumbled upon a very interesting bug. Effectively, the bug allowed the player to create walls that could trap unsuspecting baddies. Very interesting indeed.




A few experiments and 9 levels later, I found that the trap mechanic allowed me to make some modestly interesting puzzles. I won't spoil the levels here though. Go play the game!

http://kwarp.com/portfolio/astargame.html





Sunday, March 21, 2010

Computer Graphics

Here's some cool Computer Graphics projects I've worked on this semester:


In this assignment I wrote a variant of the Midpoint Algorithm to draw lines. You can also toggle attributes such as color, anti-aliasing, and line weight.


Here's a cool Wireframe renderer. I wrote Matricies that handle all the transforms from Object Space to Screen Space, and everything in between. I threw in my animated robot dude for good fun, and a slider that moves between a pure perspective and orthographic projection. With a perspective projection, objects farther away seem smaller and converge at a vanishing point. On the other hand, orthographic projection has no vanishing point at all.

I wrote the programs using a Java-based work environment called Processing. It's very easy to get started making cool stuff. Check it out.

Monday, January 18, 2010

The Factory Project

Last semester, I took a Computer Science course about concurrent programming using the Agents. For my final project, I was put into an eleven-person programming team and tasked to design a way for robots to assemble kits in a Factory in 6 weeks. I have put together a walkthrough video of our results:



The five of us in my CSCI 201 class worked on the system design and backend. The other six people were in CSCI 200 class and coded the GUI components.

Our team was very strong, and chose to go well beyond the requirements for the assignment. We chose to make both the machines and the intelligence (making decisions for the machines) operate on separate threads, accurately simulating how a real factory would behave. There are approximately 43 threads in this program.

I decided to try pair-programming with one of my team mates on this project, which turned out to be the best idea ever. We designed pseudo-code for key parts of the system in a single night, and comprehensively worked through the code on paper (and an excel spreadsheet) to insure that the logic worked out. From there, coding was trivial.

The most difficult part of the project for me was designing the behavior for the Factory's FeederController. During runtime, the FeederController cycles through four major part-feeding states. At any time during any of those states, the Feeder could be interrupted with a command to feed a new type of part (or parts). The challenge was designing a system intelligent enough to appropriately respond to new commands under any circumstance.

Unit Testing was an unexpectedly lengthy ordeal, eating up a couple days of my life and 1700 lines of virtual paper. In hindsight, such a comprehensive Unit Test was absolutely necessary. I discovered several behavior-breaking bugs that would have been impossible to detect after integration with the rest of the team. In fact, after integration, my tested components of the system worked almost exactly as expected, and suffered significantly fewer problems than the horror stories I heard from other teams in the class.

While the resulting Factory simulation doesn't look as cool or flashy as the games on my website, it was a worthwhile team experience that dealt with some very difficult programming designs. Additionally, the tools I gained experience with, Subversion, Team Wikis, and Unit Testing, will be indispensable on future programming projects.

Sunday, January 10, 2010

3D Animation Reel

During the Fall 2009 semester, I took a 3D animation course that let me dabble in modeling, texturing, animating, and lighting 3D objects. I've put together a quick reel of some of the more interesting stuff I worked on.



The two big subjects the course introduced me to were animation and lighting. I really enjoyed animating in Maya; it breathed some much-needed life into my (otherwise static) creations. The lighting process is sort of a mixed bag. My 3D objects looked absolutely stunning when lit correctly, but the actual process of lighting an object well took a lot of practice and patience.

Overall, I learned some powerful techniques in this animation course that will serve me well in future 3D game projects.