Sunday, November 7, 2010

Space Escape Going Public

The new menu features a new ship and darker music.

The Warhawk soundtrack got my imagination churning so I could make a game like Space Escape. It would be copyright infringement to include the music in a public release, but probably moreso if I were to throw the music into a Github repository, where files can be directly linked.

In comes Kevin Macleod with some pretty good boilerplate music that I can toss into the game and even distribute via Github. This is because he licenses everything under Creative Commons. Another artist who made the nova texture also adds to my delight here.

After some adjustments to the credits and such, I am now able to publicly release the Space Escape repository.

The new space ark

The starship model I was using won't work here, because I don't have distribution rights (even though it's free usage). That's ok, because it didn't survive the import from Unity 2.6->3.0. I have an idea for a better fitting starship anyways, so you'll see that included as well.

Although the planetary textures aren't covered under something like the Creative Commons license, a quick and polite email to James Hastings-Trew over at the Planet Pixel Emporium got me permission to toss it into the game.

Wednesday, October 20, 2010

Droids - Spawn Points with Gizmos

Enlisting the Unity editor to help create content is a powerful feature. In my case I wanted to create some spawn points for some work stations as part of my droid factory. The work stations are spawned in random locations. The possible locations are pre-determined (my spawn points). One thing I didn't want to do is fidget with these points to get the location just right. I wanted something that lets me spend as much time as possible in the editor.

My solution was to draw an approximation of the model using the editor. To top it off I pulled this information from the prefab itself. This code also includes finding a prefab and using its data without there being an instance of it. I also had to filter out game objects that weren't prefabs (otherwise the editor will draw those).

Here's the code:

This is how it looks:
Yellow spawn points indicate where objects can appear

Monday, October 11, 2010

Droids - Can't send RPC function because the target is not connected to the server.

This is a fun little bug that resulted from me trying to call an RPC method when it was targeted at the owner itself! To work around this I checked to see if the target player had the same GUID as the Network.player. If it was the same I'd call the normal local method rather than the RPC. I found out about this here.

By the way, fixed player spawns are up the Droids github repo now.

Thursday, October 7, 2010

Droid Colors

3 colors for 3 players
Adding colors to Droids proved to be a lot more difficult than I had imagined. Sending all of this data as a one-shot RPC call on player connect was just creating a maze in my head, and things weren't working quite as I had expected.

My ultimate solution was a combination of wasteful serialization and some RPC calls. The server is the only app that handles color management. It also now tells clients when to spawn their droids. When the droid is spawned, it immediately sends out an RPC telling that client to change its droid's color to whatever color it assigned for that player (keyed by player GUID).

Clearly, green is hacking here.
That alone was not enough, however. New players joining wouldn't get old player data. Using the OnPlayerConnected event to fire off colors to joining players didn't seem to cut it. In the end I just added a new NetworkView, tied it to the DroidColor, and added an OnSerializeNetworkView to send the color segments over the wire. In the future I'd like to cut back on state sync, but at this point I'd rather move onto other features and this just might be over-optimization.

As normal, the new version of the Droids game (web and stand-alone builds) are up in the games section.

Friday, September 10, 2010

Sword Tag

After a few solid sessions, I feel I can safely say I'm back in business for attending sword tag. I've done some googling around and found the act of fighting others with boffers is usually referred to as sword tag (what I do is just one of the variations of it). So far we're up to five regular attendees, with hopefully more on the way.

I've created a Facebook page for Sword Tag to host the videos, pictures, and discussions. It doesn't have the spam or hosting problems that running my own PHPBB2 setup would incur, nor any monetary costs. I understand a lot of folks have a lot of privacy concerns about Facebook, but I don't believe you're any worse off than vanilla forums if you create an account just for the means of hitting the fan page. This way, I can make sure my time is spent constructing weapons and stabbing, rather than maintaining a page that only five people use.

I found the name Sword Tag Google group through some searching. I've previously seen it called "rogue field", "fight night", and "fighter practice". None of those really did a great job explaining what they were about nor had any internet momentum behind them. The biggest difference I've seen with that site's rules and ours is that we're actually a lot more strict when it comes to safety for most things. For example, we don't pad our spear hafts, but we use the electrical PVC pipe (gray), because the white/irrigation PVC shatters when it breaks. I believe their rules also allow for rattan sticks and such whereas we do not. We also don't allow metal of any kind, whereas they use bolts in their shields.

In closing, we have a really good core group so far and are actively looking for more folks. If you have an interest we more than enough weapons for many people to use with the ability to create more in a very short amount of time. Doing it yourself is cheap and going out there requires no special clothing or gear, it's certainly a lot less investment than any sport out there I've seen.

Wednesday, September 8, 2010

Droids Available

I've updated my web player and uploaded some standalones for the Droids game. I'm fairly convinced that hosting on the web player doesn't work, but feel free to try.

Sunday, September 5, 2010

Droids - Today a Robot Must Die

Robots need to die, or soon they will enslave us all.
Or at least, droids that shoot other droids need to get shot and die as a result.
My droids are now exploding a rather fun fashion, with physics included! Since my model is composed of many Blender objects, the droid isn't a single mesh but a series of game objects tied together. On the droid's death I add a RigidBody to each part, as well as a Collider whose mesh is the MeshFilter's mesh. After that I unparent the parts from the model. Then I can apply forces as I wish!

I didn't want to have the parts interact with the CharacterControllers of the living players. CharacterController is a subclass of Collider, but I couldn't get it to work with Physics.IgnoreCollision(), and I'm not the only one. Embracing the limitations and assumptions your framework uses is a very key step to moving forward. Writing my own CharacterController may be in the future, but in a 3D environment I believe that's a lot of work - work I don't want to put in right now when I could be fleshing out game ideas. My workaround was to make the Z scale on the platform longer. When a droid dies I translate it's Z away from the camera. In an orthographic view, this has no effect on the visual. Because I'm constraining the parts to only explode along the X/Y axises, the parts "behind" the living droids never touch. Since there's no interaction I can keep this all client-side. There's no need to sync explosions (other than a single RPC call to notify the clients of the death). I actually scoot the dying droid so some of it hangs off the edge of the platform. This makes some parts hit the platform, others fall. The body usually tips and rolls off. These are all great effects for very little work.

Here's the core of the code:

Saturday, September 4, 2010

jQuery + OData - The Code

I've added the Github repository for my previous post regarding using jQuery and OData (WCF Data Services) in .NET. The original post has been updated as well.

Friday, September 3, 2010

jQuery + OData

Some stuff I've been learning at work: jQuery+ OData! There's little docs on this, and what's out there is hard to get working. After numerous headaches, I found a way to get it working. You can grab a fully working example on my Github account.

Here's the recipe I used to create the app:

  1. MVC 2
  2. Add jQuery reference to Site.Master
  3. Add jQuery.Tmpl plugin to Site.Master
  4. Add json2 library to Site.Master
  5. Create ADO.NET Entity Data Model
  6. Add tables and fields as desired
  7. Publish SQL to your SQL server
  8. Create a WCF Data Service
  9. Set your entity access rule to "*" and EntitySetRights.All
  10. Disable WebDAV for your app
  11. Build the app
  12. Client-side code

There's a few neat things you get out of this. One is that your app is RESTful. REST is just a philosophy, but adopting it can make life really easy as it does here - jQuery is able to communicate with the server without any special tools (save the templating plugin, but that's so we're 100% client side). We're just sending JSON back and forth and using HTTP Verbs (that's all REST is, distilled). The particular structuring isn't defined by REST - it's OData. OData best thought of as a REST implementation. It also includes a query format so I can ask for certain kinds of objects, only certain fields, etc. Just to give some background, OData is an open standard that Microsoft is behind. The OData site itself has links to libraries used in many different languages, not just the .NET variety. Netflix uses it as well, and you can query movies in all different kinds of ways using their public OData API.

There seems to be a lot of cool things about OData, but the things that are interesting to me is that there's no work on the server-side to support different formats such as XML and JSON. Ask for what you want in the request type and you get a response back the way you wanted. You can filter what kind of objects you want server-side or even just pulling certain fields back using a query string. Again, there's no work on the server developer's end to support this.

Documentation and examples can be given freely with the jQuery code I have. One of the PHP or Java guys could pick this up and use it on their client side or figure out how to do it server-side by interpreting a language all web developers must learn: JavaScript. If they stick to client side, they have super easy examples.

I also don't have to get nitty gritty with MVC and how it handles me moving between pages and the like. I can be a one-page app very easily here.

The data service classes provide hooks for intercepting queries and sets so you can ensure validation, add additional constraints, and strip constraints to prevent DoS attacks with expensive queries. I haven't gotten into the details of the server-side yet.

1) Create MVC 2 Project
This is pretty self-explanatory (:

2) Add jQuery to reference Site.Master

Microsoft and Google host jQuery. This means you can add a JavaScript reference without even having to add a file to your project.

<script src="" type="text/javascript"></script>

3) Add jQuery.Tmpl plugin to Site.Master
This you'll need to snag from Github. At time of writing, the plugin only works on Firefox, but one of the other forks likely fixes this issue (it's an easy fix, but why not get all of the other community fixes?). nje's fork seems to be the most current/active, so we'll grab that. I like to use IIS to host my apps locally so I can get deployment issues out of the way. It also means I can refer to webservices and the like without having to worry about the port changing on me, or the app turning off because I didn't touch it every few minutes or leave my IDE running.

Without IIS:

<script src="Scripts/jquery.tmpl.js" type="text/javascript"></script>

With IIS:

<script src="ODataPrototype/Scripts/jquery.tmpl.js" type="text/javascript"></script>

4) Add json2 library to Site.Master
Same as #3 with regards to IIS. This is the official JSON library. Use it like so:
Without IIS:

<script src="Scripts/json2.js" type="text/javascript"></script>

With IIS:

<script src="ODataPrototype/Scripts/json2.js" type="text/javascript"></script>

5) Create ADO.NET Entity Data Model
Others have explored this in detail. We just need to create the edmx. I have to remind myself that this is the container I'm naming, not the table/entity. I named my data model as ODataPrototypeDb.

6) Add tables and fields as desired
The Entity framework calls database fields scalar properties. I'm going to name my entity as User and add the fields FirstName and LastName (strings).

7) Publish SQL to your SQL server
This can be done within Visual Studio pretty easily. Right click on your Entity designer and click "Generate Database from Model". The wizard will help you get your connection string configured. You'll need to create the DB manually (and ensure permissions is necessary). I configured it against my localhost and used Windows Authentication. After you finish the wizard, it'll generate a .sql file. You can execute this from within the IDE itself. Right click on the SQL editor in Visual Studio -> Connection -> Connect. Once connected right click again -> Execute SQL. Now all of your tables and fields should be configured! Be aware that you can update your Entity Data Model and push those changes back to the DB, but doing so as I described above will drop your tables and recreate them. You'll want something more intelligent after you've made it into production (:

8) Create a WCF Data Service

Add a new item to your project. Under the Web category is WCF Data Service. I named mine PrototypeDataService. Generically point the data service to the Entity container type made above (not one of the entity types itself).

9) Set your entity access rule to "*" and EntitySetRights.All
This will allow all entities to be read and written to in any manner. In a real enterprise app we'd constrain this a bit. You can just uncomment line 18 and change it to accomplish this.

10) Disable WebDAV for your app
WebDAV will swallow any HTTP PUT and DELETE verbs. This will prevent you from updating and deleting entities via your RESTful OData service. To disable WebDAV for your app, just add this to your web config under the configuration node:

This will only bite you in IIS, but you have to eventually deploy to IIS anyways. Why not also run in IIS locally in your project settings so you can feel these pains earlier? (:

11) Build the app
Ctrl + Shift + B - After that you're only doing UI. No more build/run as part of your dev cycle. Just save/run.

12) Client-side code
In your home page, add the JavaScript example. I've included the entire page. I made my changes in Views/Home/Index.aspx, which is the root page of the app.

Example of doing CRUD with a WCF Data Service using OData + jQuery (all client-side code):

Misc tips:
Add this line to your DataService to get descriptive errors back from the service while you're debugging.

To Get IIS working nicely, I had to set the identity for the default app pool (ASP.NET v4.0) to my logged in account, because that's the owning account for SQL Server.

Big thanks for Scott Hanselman for introducing me to jQuery + OData during this talk.

Friday, August 27, 2010

Droids - Shooting

This droid is shooting some kind of lethal glitter attack
I've made small progress with the Droids game. Something to note while playing around was that the CharacterController didn't do much for collisions beyond its movement checks. I added a capsule collider to it that matched the CharacterController's internal collider. This allowed my shots to detect their collision with the droids.

When destroying network shared game objects with Network.Destroy(), be sure to check the networkView's isMine property, otherwise you'll destroy it twice, and Unity doesn't like that.

I haven't updated the web player yet, but the code is still on my Github page. I'll likely update the web player when I get networking working well with it, but for now it crashes due to security problems inside the web player.

Sunday, August 22, 2010

Droids! + Dead Reckoning

I developed a strange addiction to Castlevania: Harmony of Despair recently. During the last IGDA game jam, kindly hosted at UAT, I sought to explore what kept me so drawn to a game a game that felt fairly basic.

I spent a good deal of time trying to make a platformer that would exist within a Dyson sphere. Unfortunately, Unity's CharacterController class, while awesome for a great many things, doesn't work well if your concept of up is a variable thing. I could write my own CharacterController, but I know it's a lot of work. Just seeing what I could do with the existing controller ate most of my time while at the game jam, leaving me with just a single untextured robot made up of cubes and cylinders warped into a mockery of a mechanical being. It could jump, yes, but there were bugs.
Why Droids? I'm not very great with modeling/animating/rigging. Robots need little to no rigging at all, if designed right. I can also have robots do things that normally just don't make sense for carbon based life-forms, and it won't break immersion. In other words, I can focus easily on making the game fun.

I've had a little time to work on it, and I've produced some satisfactory but less than amazing results. My game is now networked, borrowing heavily from my progress on Spell Blade. An interesting thing I discovered in all of this was how easy it was to implement dead reckoning using Unity's network serialization event. The game plays quite smoothly over the network.

This code does a read or write depending on who is controlling the droid (different players control different droids). The outbound is pretty simple. I serialize all of the relevant stateful data (location, orientation, desired movement over x/y, etc). Inbound is just about as simple, but the other half of this is that the remote player's input comes from the network. Since I knew at time of sending that the player was trying to move full-speed to the left, I'll give that same input to the robot until I get another update, where the location, orientation, and desired directions all get forced to new values. Maybe the player rapidly changed directions or something, in which case I might see some jerkiness depending on lag. What I definitely will see is the game moving the droid smoothly when the player is moving relatively smoothly, which I expect will be happening a lot. This isn't perfect, but it sure beats watching the player snap positions as he moves across the screen.

Each droid is controlled by a player over the network,
using a simple platformer scheme
Where do I go next? My plan is to demo this to my gaming group and ask "What would you like to see?". I've seen games evolve into some really wonderful things when designed this way. I believe I'm at a pretty good point here to do that.

Try the game here. I haven't been able to host any Unity games yet via the web player, but I test joining as a client with the web player all of the time. I'm using port 6112 if you're having connection issues.

You can also check out the code here.

Friday, August 13, 2010

Space Escape 2 Progress - Milky Way

Even while working on the first Space Escape I spent a good amount of time just looking for a way to make a Milk Way skybox, featuring, you know, stars. I did get an ok skybox with some rather ordinary looking stars.

I was able to find some fairly high res images of the Earth's night sky as a panorama. How to make a skybox out of that? The stuff I found mostly involved tossing the panorama on some sort of sphere or dome and then rendering that six times (one for each side of the skybox) to an image. This seems pretty hacky to me. Perhaps I just don't know how to wield Blender enough. I don't have Maya/Max, or a full version of Photoshop, so my options are pretty limited.

Instead of doing a skybox, I instead made a sphere with its material set to Particles/Alpha Blended. The sphere is set at 0, 0, 0 under the main camera, so it follows your view around everywhere. I had to turn off the collider so I wouldn't get problems with flares (which come fromt he sun). Everything in the game has a large or far scale, so I made the sphere very large. Unfortunately I can make it really large in the game world (where I can adjust the far clip plane of the camera), but it can make navigating in the editor a little clunky.

If an artist helped me out I'd certainly welcome it, but at the moment I can move forward, and that's what counts.
Having the Milky Way streaking across the view really adds to the look of the game.

Friday, August 6, 2010

Space Escape 2

While you're safe in the middle, there's a faint green ring around you
I have discarded Space Escape. The game and related posts will remain up as historical evidence that I have indeed worked on games before. I aim at a total reboot. The concepts I liked have been packed into a suitcase and we're now off to another location entirely. I present the beginnings of Space Escape 2. Perhaps I am fickle. The exhibits are laid bare for your judgement, but I believe the net result will be a more succulent fruit than the first iteration.

I initially really liked the idea of flying your ship through a virtual corridor, plotted by your ship's systems. This seems difficult to do when you can arbitrarily fly anywhere. That feature will be removed, and in its place you'll find you can move about in a radius freely, while I take you on a powerful trip.

As you start to leave the virtual lane, it brightens up and becomes yellow. Wouldn't it be great if we had this for cars?
I liked the idea of the boosting away. The act of acceleration seeming to tear at your very senses. This was difficult to accomplish, and positioning your ship just right to perform the maneuver was far too much delay and not enough gratification. My plans are to keep the boost, but make it more or less automatic, and guaranteed.

You'll also notice how close to the Earth the ship is. It should feel pretty big. It is pretty big. It houses billions of people with lots of room to spare. Compared to our sun it's actually pretty small, but I can still pull that off. I believe the baffling scale of the cosmos will be even more apparent now.

Ah! Too far!

Ok, so it's not enforced yet.

Saturday, July 31, 2010

Space Escape Progress - Sling Shot Boost

Space Escape is at that point where new features are pretty easy to add. I've been getting some feedback and making adjustments I feel are for the better. The ship should be much easier to steer now, along with more powerful thrusters. You can even fly away from Earth directly now. However, that won't get you the big boost in speed.

The hard sci fi feel to the game will start to break down here. I haven't put any fluff behind it yet, but I've added a gravity drive. It isn't just another means of moving through space, it actually picks up strong gravity fields nearby to propel the ship. The effect you'll see from this is the closer to Earth you are as you slingshot around it, the more of a boost you'll get. The effect is multiplicative, so even edging just a little closer can mean a lot. When the engine kicks on I warp the screen by increasing the field of view on the camera. I also start a looping sound effect. It actually sounds like it's revving up (or spooling, or just growing), and all I had to do was change the pitch. These values need a lot of tweaking though, as too much field of view and too much pitch can ruin the effect.

Can you beat this speed?
Overall I'm still pretty happy with the progress. I wish I'd had the game in a state to get feedback sooner, but getting the theme of the game down was pretty important to me on this one. That's one thing that's changed little. I must admit, now that it's gotten this far, I'm not sure if I want to put it down. I want to move onto the next game, but I feel like I'm over a hurdle and it's more fun than before to just keep adding features and shine.

Thursday, July 29, 2010

Space Escape Progress - Victory(!) and Navigation

Amber is a common HUD color, and it doesn't mix with the green.
With this new sitting of Space Escape I've added two new key features: The ability to win the game and some more navigation assistance.

Victory comes when you simply pass a certain distance away from the sun. You'll be returned to the menu upon completion. I would like to eventually add some performance data.

The navigation assistance I thought was pretty helpful. The amber rings appear to be a projection of your onboard HUD (much like the compass). While you don't need to fly through them to win, they certainly can give you an idea of how it works.

There's still some polish to add, but it's starting to feel like a full game. This comes in good time, as I can feel my motivation begin to wane. I'd like to move onto some other games. I can feel the itch (:

Wednesday, July 21, 2010

Space Escape progress - the compass

I like the idea of a game world and HUD being stitched into the same universe. It seems to meld well in a sci-fi setting as well, where you can easily understand a computer rendering a lot of data on some display for you, plus a bunch of extra stuff. Minus the interpretive sensors, your computer does this already.

I felt like this could be pretty useful in Space Escape, because where your ship aims is not necessarily where you are going, and having your bearings relative to the Earth is pretty important when one is setting out to do a gravity assist maneuver.

After some work, I turned up with this:

Degrees show exactly what it's for, and it follows the Earth as you move about.
This is artwork I am capable of doing from front to back. I used Blender and its cylinder prefab model. To make it so the number you are facing is not mirrored, I inverted all of the normals. The texture is painted within the inside of the model. While working on this I found out that both Blender and Unity support Photoshop's preferred PSD format. This makes it nice because I'm always a save key-command away from seeing my work in-game. To get the texture to appear as it does in the game itself, I had to set its material to particles/additive.

I'm not familiar with how Quaternion rotations work, and I'm still wrapping my head around some of Unity's rotation math. Getting the right kind of code took maybe an hour of actual work, but this is the behavior that drives the... behavior:

All of this is viewable from the web player here.