by Firedroid

Archive for the ‘Unity’ Category

As our development progresses we’re closer and closer to a version that supports puzzles and can be played as a game (although it’ll be a work-in-progress). So we’ve had to think about how we’re making those puzzles and how to feed them into our game. Now we already stumbled upon the Tiled Map Editor, which is a free and opensource mapping tool for games that are based on tilemaps. We filed it away as a great tool for later use, while we focused on the basic elements of the game.

Recently that core has become complete enough to warrant a second visit to Tiled and see how we could use it to build our puzzles. We made a tileset and set to work!

First up is handling rotation. The tileset has four different versions for straight lines and corners, as they can go up, down, right or left. We only have one 3d model for such things, so they needed to be mapped to the tileset. We thought about building fancy and complicated solutions but in the end we simply used an array with objects that contain information about the tile. Each tile in the tileset is coupled with such an object, which holds information like rotation, direction, height, etc, everything the engine needs.

Tiled outputs an XML file containing the information about the map size, layers and tiles in it and after fiddling with some Unity scripts people wrote we decided to just use C#’s native XML functions. In the end this works really neat and we’re very happy with Tiled as our tool for building levels since it’s a good map editor for our needs.

On the tech side this has been a productive week. Last week we implemented placing fans and having fans influence the ship’s route through the level. This week we expanded on that, implementing the wind indicators and fixing a bug with the ship’s roll.

After that we heard that our Unity iOS licence was about to get ordered, so the focus shiften to rotating and moving the camera around and about on the playfield. We were still using buttons and since the iPad has none of those, it was important to have it done by mouse since it’s a small step from mouse location to finger location.

Later into the week we added the four fans on the right to check whether we could easily add fans that followed the world’s rotation, seeing how we want to set limits to the amount of fans per direction available to the user.

So there you have it! The camera can now freely move and rotate by using the mouse and fans work nicely.

The basis for our game is a grid of tiles. In our setup we’ve got a grid and tiles, with every tile aware of its neighbours (left, right, above, below). This makes lookups for determining the next tile to navigate to faster and easier.

The airships need to navigate this grid and turn away from mountains (because that’s what the airstream does). While navigating the grid we want the ships to move exactly one tile per ‘tick’ (a tick is a arbitrary amount of time, the rate at which ticks go by basically control the speed of the game). This isn’t very hard, all we need to do is make the ship pick a new tile when a tick has passed. Movement still needed to be smooth however and since we will be making turns and moving up and down, simple interpolation wasn’t going to work.

So we’ve chosen to use Bezier Curves to move our ships. The basis for this system is that the ships should move on the current tile towards their next tile, with the beginpoint being between the last tile and the current tile, and the endpoint being between the next tile and the current tile:

The begin and end points (p0 & p2) are shown in yellow, with the control points (p1 & p3) being shown in green, with lines from the begin/endpoints to them in green as well. The blue line is the bezier curve itself, and the red point is the ship’s position. The ships current direction is shown as a red line.

I’m quite happy with the way this turned out, the ships seem to move naturally. Of course there’s a lot to do to make the ships movements appear more natural, such as swinging from side to side, bobbing up and down a bit, etc. Still, this is a very nice basis for movement and I hope it’ll continue to work well.