[Score.] Shoutout

Hey Guys,

A good friend of mine, Greg Weaver, has been promoting his new blog on video game music insight called [Score.] over at http://scorevgm.com/ and I wanted to give a quick shoutout. He composed the soundtrack for IceBreakers and the piece I was using in my Starfox demos. So check him out, he’s got some great stuff!

Posted in Starfox | 1 Comment

UnrealScript Camera Tutorial

This is in response to Marti’s comment. Thank you Marti for your code request!

This is a very basic tutorial for implementing a custom camera in the UDK using UnrealScript. I will be using examples from my Starfox game as well. In order for the UDK engine to recognize and start using your camera class you need to set up a few things.

GameInfo

You will need to first set up a class that extends GameInfo, in my case I just named my class MyGameInfo.  Here, you can tell the UDK which classes to use as the controller, which class to use as the default pawn, as well as which class to use as the HUD. For our example we just need to tell it our controller class, in my case it’s MyPlayerController. This is going to be done in the defaultproperties section.

class MyGameInfo extends GameInfo;

defaultproperties
{
	Name="Default__MyGameInfo"
	PlayerControllerClass=class'MyPlayerController'
}

PlayerController

Next, you will need to make the MyPlayerController class.  This class is closely coupled with the default pawn class. I find that a lot of logic for reading in player input and then taking action on the player is found in this class. My class contains logic for determining when bullets are shot, when bombs are shot, calling barrel roll on the player, telling the player to lock on a target, etc. The only important thing for this tutorial is telling UDK which camera is linked to this controller. My class is just MyCamera, again, you can use any name you wish.

class MyPlayerController extends PlayerController;

defaultproperties
{
	Name="Default__MyPlayerController"
	CameraClass=class'MyCamera'
}

Camera

Alright, now we can use our camera class. Make sure your class extends Camera, but other than that I only found one important method that must be overridden to in order to update your camera.  This is the UpdateViewTarget function, which is called by the engine every frame.

class MyCamera extends Camera;

function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
	//your camera logic here
	//...
	//make sure to update OutVT
	//OutVT.POV.Rotation = myRotation;
	//OutVT.POV.Location = myLocation;
 }

In this method, write your logic for your camera and when you’re done, simply update the parameter ‘OutVT’ with your final Rotation and Location for your camera.  Rotations are always represented by the Rotator struct, and Locations are represented by the Vector struct.

Notes

You might see a lot of coding tutorials where they extend UDKGame instead of GameInfo, and UDKPlayerController instead of PlayerController. This is OK to do as well, however, this will include a lot of gaming logic pertaining to Unreal Tournament and the FPS genre. I often found that the engine was trying to do a lot of things behind the scenes that was taking control away from me, and I would get lost trying to fix them. Since my game is very different from an FPS I choose to extend from the very generic GameInfo and PlayerController classes.

StarFox Example

I’ll post my game’s camera code next. Let me know if I helped, or share your own story by posting a comment in the comments section. Thanks for reading!

class MyCamera extends Camera;

//member variables
var MyPawn cameraTarget;
var int cameraDistance;
var BoundingPlane myBounds;
var bool bInitialized;
var Vector myLocation;

/**
 * Custom method for setting up camera.
 * Setup initial location.
 * Setup custom bounding box (camera used to be bounded,
 * but now it just holds information about the center of the screen)
 */
function Initialize()
{
	//top left of the bounding plane
	local Vector topLeft;

	//setup initial location
	myLocation = cameraTarget.Location;
	myLocation.X = cameraTarget.Location.X - cameraDistance;

	//create bounding plane
	myBounds = new class 'BoundingPlane';
	myBounds.width = 1000;
	myBounds.height = 400;
	topLeft.X = myLocation.X;
	topLeft.Y = myLocation.Y - (myBounds.width / 2);
	topLeft.Z = myLocation.Z + (myBounds.height / 2);
	myBounds.topLeft = topLeft;
}

/*
 * Main update function for camera, gets called by engine.
 */
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
	local Rotator myRotation;
	local Vector origin;
	local float rotationPercentage, panningPercentage;

	//grab the player
	cameraTarget = MyPawn(PCOwner.Pawn);

	//now that the player has spawned
	if(cameraTarget != none)
	{
		//initialize camera
		if(!bInitialized)
		{
			Initialize();
			bInitialized = true;
		}

		//follow player if alive
		if(cameraTarget.bAlive)
		{
			//camera's freedom
			rotationPercentage = 0.15;
			panningPercentage = 0.6;

			//adjust rotation
			myRotation.Pitch = cameraTarget.Rotation.Pitch * rotationPercentage;
			myRotation.Yaw = cameraTarget.Rotation.Yaw * rotationPercentage;

			//adjust location
			origin = myBounds.topLeft;
			origin.Y += myBounds.width*0.5;
			origin.Z -= myBounds.height*0.5;
			myLocation.Y = (cameraTarget.Location.Y - origin.Y)* panningPercentage + origin.Y;
			myLocation.Z = (cameraTarget.Location.Z - origin.Z)* panningPercentage + origin.Z;
			myLocation.X = cameraTarget.Location.X - cameraDistance;

		}

		//else watch player die
		else
		{
			myRotation = Rotator(cameraTarget.Location - myLocation);
		}

		//Output values
		OutVT.POV.Rotation = myRotation;
		OutVT.POV.Location = myLocation;
	}
}

DefaultProperties
{
	DefaultFOV = 90.f       //default is 90
	cameraDistance = 280    //distance behind player
	bInitialized = false
}
Posted in Tutorials | 22 Comments

Requests

Hey guys, I need your help.

I’m really excited to hear that I’ve been getting a few requests for tutorials and code samples regarding the Starfox game on the UDK. I would love to help, but I have no idea where to begin. I have done too much work to explain everything I’ve done so far, also, many of the requests are too vague for me to handle. Also, I’ve been slow keeping the blog up-to-date with new posts.

So, here’s where you can help me.

Post some specific questions about the Starfox game, or any of my games really, or maybe some problem areas that you’ve run into in your own journey with the UDK, and I’ll see what I can do to help! If I get some feedback, I’ll be motivated to get some work done :D

Right now I’m sort of posting random thoughts I have here and there about things I came across through my development.  I’m not too sure if I’m helping anyone or not, heh.

Ask me questions, ask me questions!

\/ Comments are riiiiight down here \/

Posted in Starfox | 3 Comments

Release 2010-09-29

I put up a the latest version of the game. You can download it here. Controls are:

  • mouse to move
  • left click is shoot, hold left click for lock on
  • right click is bomb
  • A and S to turn, double click A or S for barrel roll.

Some things still don’t work, like the restart level button.

Posted in Starfox | 2 Comments

Barrel Roll

  • Rolling Left/Right
  • Rolling makes you turn faster
  • Barrel Rolling
  • Barrel Roll reflects lasers
  • Sound Effects for Barrel Roll / Reflecting
  • Texture animation for Barrel Rolling

The only weird/tricky thing I noticed when coding this is figuring out how to update the player’s Rotation.roll. If you try to change a Pawn’s roll, it doesn’t work (at least for me it didn’t), instead I keep a reference to the mesh of the ship itself, and I call SetRotation on the reference.

	var StaticMeshComponent staticMesh;
	...
	local Rotator nextRotation;

	//360 degrees left at barrel roll speed
	nextRotation = staticMesh.Rotation;
	targetRotation = MIN_ROTATION-MAX_ROTATION;
	nextRotation.Roll = MyFInterpTo(nextRotation.Roll,targetRotation,DeltaTime,barrelRollSpeed);
	staticMesh.SetRotation(nextRotation);

Side note: min and max rotation are set to -32768, 32767 respectively. I like to think of -32768 as -180, and 32767 as 180.

Posted in Starfox | Leave a comment

Items and Sounds!

Hello again!

I have been slacking in my development these past 2 weeks, however, I did manage to come up with an update. This week: items and sounds, and also a new game resolution!

I added two items to the game, silver rings and bombs. These act pretty much the same as in the original game, rings give you health and bombs give you.. well bombs.  There weren’t too many hiccups along the way, but I did spend some time trying to have items spawn from an event in kismet. Also, I found a new toy in the kismet, the Delay node. If you look carefully, the player earns a bonus bomb by flying through the 3 rings early in the level.

That may be a bit overdoing it for just one bomb event, and I did see a node called a “Counter” in the Kismet, but this way was very intuitive to me and didn’t take very long.

Also, sounds! I hope it was noticeable.. the level seems so much more happening now. Here’s a list of the sounds that were added:

  • bomb deploy
  • bomb explode
  • charge a plasma shot
  • fire plasma shot
  • plasma shot explode
  • grab a ring
  • grab a bomb
  • unlock an event
  • and lock onto a target

The last one there is actually a keycard swipe, not the best fit, but it sounds so cool. Thanks, Natalie for finding all the great sounds!

(All the sounds are from http://www.freesound.org/ we are compiling a list to credit all of the creators of the sounds)
Posted in Starfox | Leave a comment

Thumbs up

Some gold farmers like to float in mid-air and make shapes. Today they are making a thumbs up to let us know its alll-right.

Posted in Gaming | Leave a comment

Bombs, Camera, and Events

Core changes:

  • Revamped the camera, it now is a little smarter, following the player and allowing for a lot larger range of freedom of movement around the level.
  • Added bombs to the game. Bombs can be used with ‘x’ or with the right mouse button.
  • Figured out how to make a volume in UDK trigger an event (waking up sleeping enemies) through the kismet.
  • Added Greg’s newest version of music.

Bugs and issues:

  • Bullets no longer block other bullets, causing them to suspend in mid-air
  • bullets can pass through the volume triggering the events
  • The charged plasma shot wont collide with terrain while being held/charging
  • Enemies no longer wiggle or shake when flying

In-Depth notes:

*I’m going to try pasting a lot of code and see how it turns out. Hopefully its not too cluttered and ugly.

Figuring out what to do with the camera was driving me nuts. I was trying to add some sort of velocity component to both the camera’s panning and rotating aspects, but everything was turning out bad. Finally, I just decided to study the starfox game itself reaaaal hard. I probably spent 30 minutes restarting the first level of starfox trying to figure out what the camera was actually doing, but I think I did a pretty good job in the end. I was making the whole deal too complicated, I just needed to simplify everything. Here’s what I ended up with:

	local Vector origin;
	local float rotationPercentage, panningPercentage;
	cameraTarget = MyPawn(PCOwner.Pawn);
	MyPCOwner = MyPlayerController(PCOwner);

	if(cameraTarget != none)
	{
		if(!bInitialized)
		{
			Initialize();
			bInitialized = true;
		}

		if(cameraTarget.bAlive)
		{
			rotationPercentage = 0.15;
			panningPercentage = 0.6;

			//adjust rotation
			myRotation.Pitch = cameraTarget.Rotation.Pitch * rotationPercentage;
			myRotation.Yaw = cameraTarget.Rotation.Yaw * rotationPercentage;

			//adjust location
			origin = myBounds.topLeft;
			origin.Y += myBounds.width*0.5;
			origin.Z -= myBounds.height*0.5;
			myLocation.Y = (cameraTarget.Location.Y - origin.Y)* panningPercentage + origin.Y;
			myLocation.Z = (cameraTarget.Location.Z - origin.Z)* panningPercentage + origin.Z;
			myLocation.X = cameraTarget.Location.X - cameraDistance;

			//Output values
			OutVT.POV.Rotation = myRotation;
			OutVT.POV.Location = myLocation;
		}

		else
		{ ... }
	}

The camera has two factors that must be handled: rotation and location. First, the camera is always some percentage distance between the center of the screen and the Y and Z of the player. The location of the player is controlling the camera, thus the camera really has no intelligence. My other methods were producing shaky camera effects, and were really all together too much of a mess. As for the rotation, the camera’s rotation is some percentage of the player’s rotation. That way, the camera shows the player where they want to travel to, instead of showing the player where their ship is. This is the same as in Starfox. I feel with this the camera moves smoothly and it feels pretty natural.

I also added smart bombs to the game, they were fairly simple since they behave mostly like the charged plasma shot and thus extends the class. The biggest difference is that you can also detonate the bomb if you press the bomb button again. I also gave the player a limited number of bombs and added it to the HUD. Here’s the small HUD function I made for the bombs:

function PreBeginPlay()
{
	bombIcon.Texture = Texture'HUDPackage.bomb_icon';
}

function DrawBombs(int count, int X, int Y)
{
	local int index, width, spacing;
	local float scale;
	index = 0;          //index for loop
	scale = 0.7;        //scale of icon
	width = 32 * scale;   //width of new icon size
	spacing = 5;        //space between adjacent icons

	//set the color to white to draw the icon
	Canvas.SetDrawColor(255,255,255,255);
	while(index < count)
	{
		Canvas.DrawIcon(bombIcon,X,Y,scale);
		X += width + spacing;
		index++;
	}
}

To get volumes to trigger an user-defined event you have to do a few things. First, In the Editor create the volume by placing your brush, and using Brush->Add Volume from the dropdown, I used a TriggerVolume but I’m not sure what is different about it. Next, you need to define a SequenceAction which will be used in the Kismet.

class SeqAct_WakeUpEnemy extends SequenceAction;

DefaultProperties
{
  // This is the name that will apear in the Kismet Editor
   ObjName="Wake up Enemy";

  // This is the name of the event that will
  // be triggered when this action is called
   HandlerName="Wake";

}

The most basic SequenceAction just has HandlerName defined. It must match exactly the name of the function you wish to call on another class. In my Enemy class I have a function called “Wake” which simply puts the enemy in the Awake state. In the Sleep state, the enemy is hidden and doesn’t perform any actions. With this class created it should show up in the Kismet. So, have the TriggerVolume highlighted and right click in the Kismet to “New Event Using TriggerVolume”->Touch. Then right-click again and do NewAction->Wake Up Enemy. And link the two together. Next, Link the Wake Up Enemy action to the objects you wish to ‘Wake’. Finally, I needed to change a property on the Touch event, I changed “Class Proximity Types” to match the class of my player. This makes it so the only object that is allowed to activate the event is your player and not enemies or bullets you shoot. Here’s my Kismet:

Posted in Starfox | Leave a comment

The Starfox Project

I am going to try and start blogging about my journey through my latest game project. I am using Epic’s UDK to create a game inspired by Starfox, there may also be a little Megaman in there somewhere as well.  I think ill start by listing my goals for the project and blog:

First off I wanted to pick up a completely new game development engine. I’ve been wanting to do this one for some time now. Engines provide so much, so much power that I have been setting aside when working on my other projects. Really, I’ve been trading functionality in my games for an easy learning curve. I feel API’s tend to be easier to work with, just learn a few functions, set up your environment, create a new project and you’re good to go! Thankfully, I’ve already been through the frustrations of the (I felt) pretty steep learning curve for UDK in the first few weeks, so I won’t be expressing any frustrations here… hopefully.

I want to create a fairly robust, complete game… minus a few assets, of course, I don’t know any modelers, animators, or texture people. I’m really trying to create something fun and interesting, creative even, mostly to show off what talent I’ve gained through the past few years.

I want to spend a long time on this. My goal I keep saying is 6 months, but really I want to spend 6-9 months or so. I’m around the 7th week or so, now. The point of this is to avoid rushing, and to give myself some breathing room. I don’t want to work every day, maybe a few hours a week, maybe a few more if I get excited :D

I’m making a blog to help document my work, mostly for myself, but maybe a few friends would like to see whatsup, and maybe I’ll get to answer a fellow developer’s question if they stumble upon my site. I’m not sure if I’ll be posting code snippets, or in general what I’ll be doing, haha, but I’ll figure it out.

Posted in Starfox | 1 Comment