07 May 2015

Top-Down and map-saving/loading

Hello again readers,


I've finally managed to make the top-down view display. I must admit, the manner in which I did it is somewhat of a roundabout kind of way, but it allows me to do interesting things in the future like custom maps (without much effort) and even procedurally generated maps(though that isn't the plan currently).

What I did first, was set up a system in my Unity editor which allows me to make a map in the editor, which I can then save to a text file. This required me to rotate the isometric map about 45 degrees though, which proved to be a slightly tricky mathematical problem for me to solve with me making a few dumb mistakes along the way.

Eventually I figured out that there is a relatively simple equation which allows me to put any tile or tile-based object(Objects which snap to a tile). To get the Text X position (Xt) on the square grid, you take the Game X position (Xg), add that to the Game Y position (Yg), then divide all that by 1.28 (because bordering tiles are 0.64 units of distance away on the X axis, and 0.64 units on the Y axis, and we are adding the Xg to the Yg, so we arent looking for the exact distance between the tiles using pythagoras and that stuff) So the formula for that is: (Xg+Yg)/1.28=Xt. To then get the Text Y position (Yt), you will want to use (-Xg+Yg)/1.28=Yt. After figuring that out, I just had a few problems with rounding which were swiftly solved, and now I can very easily turn this:
Current testing map in the editor
 Into this:
Current testing map in the Map.txt file. Can you figure out what is what?
After finishing that part, all I had to do was make sure the game loaded that text file into memory at the start of the game. Then to actually get the top-down view, I simply had to do the reverse of what I did before, which turns out to be the following formula for Game X: (Xt-Yt)*0.64=Xg. Then to get the Game Y position you do: (Xt+Yt)*0.64=Yg.

I also had to make some new graphics of course, they turned out okay, but I'm not going to win any graphical art prizes with it.

So thats how we turn this:
Isometric in game screenshot
Into this:
Top down in game screenshot of the same location. Ignore the characters, I haven't done them yet.
I didn't yet change the characters to be correctly placed nor are the graphics there proper (obviously).
But that will be a quick change and the first thing I will do next.

What all of this means, is that I can now start working on combat, and actually get this game playable (Not necessarily fun, but we will see). This also means that its quite possible that with my next blog-post there will be a playable demo! (I'm not making any promises though) Note that that combat wont have the 2D view in it just yet, I first want to get something playable out before I start doing that.

So yes, if you have any questions, feel free to ask! (Oh, and if you find any spelling or grammar errors, feel free to point them out too)

No comments:

Post a Comment