binary zoo
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 19, 2018, 01:20:51 PM

Login with username, password and session length
Search:     Advanced search
30178 Posts in 1158 Topics by 195 Members
Latest Member: dianeanderson
* Home Help Search Login Register
+  binary zoo
|-+  Game Development
| |-+  General Discussion
| | |-+  Tiles. Shapes, Distances and Stuff
Pages: [1] Go Down Print
Author Topic: Tiles. Shapes, Distances and Stuff  (Read 3193 times)
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13185



View Profile WWW Email
« on: January 30, 2013, 02:20:12 PM »

So I've been thinking over a few ideas that would require a tile map and I've hit upon the usual problems.  Namely distances between tiles and dodgy movement.

If you stick with the easy square tilemap then horizontal and vertical movement is fine, but diagonal distances are all messed up.

The normal solution to this seems to be to use hex tilemaps.  Distances to any surrounding tiles are the same, but, depending on how you arrange the tiles, you can't move either horizontal or vertical without doing a weird zig-zagging.

So how about a diamond/rhombus as a compromise?  The diagonal distances aren't quite right but better than a square map and you can move horizontal and vertical without the nasty zig-zag effect.

Am I missing something?  Is there a better solution?


* tiles.png (36.18 KB, 564x198 - viewed 280 times.)
Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #1 on: January 30, 2013, 04:57:23 PM »

I'm a little confused as to your problem.

Tile center to Tile Center movement is easy enough, depending on the movement constraints you set.

Why does the varying distances between tile centers matter ?

Surely, you would hard code movement distances whatever tile system you use, Hex, Square, diamond ect for the relevent direction.

I'm assuming you want to jump to the adjacent tile center.  (step movement)

Even if you want smooth movement between tiles the distances would be hard coded for the direction.

If you need to calculate the total distance travelled over a series of tiles and arbitrary directions you could step through each tile from the start to the finish and add each distance to a total.

I wonder though, if there is a repeated polygon shape that would allow for diagonal, horizontal and vertical movement with equal distances.

It's an interesting problem and given that tile based games have been around since the dawn of computer games you would think that there is a standard solution to this.

This is a really useful website.

http://www.ics.uci.edu/~eppstein/junkyard/topic.html

It covers topics such as tiling, but i don't think there is a specific solution to your problem.

TMC
« Last Edit: January 30, 2013, 06:16:56 PM by T_M_C » Logged
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13185



View Profile WWW Email
« Reply #2 on: January 31, 2013, 07:52:08 PM »

Yeah I didn't explain that well Smiley  Essentially it's not a coding issue, more a one of geometry.

I wonder though, if there is a repeated polygon shape that would allow for diagonal, horizontal and vertical movement with equal distances.
Yeah that's pretty much what I was getting at.  And I'm possibly being unnecessarily anal about it.  I was just trying to think of a way to making movement distances in all directions realistic while remaining grid based.


Nice link.  I'll have a bit of a browse.

Logged

fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13185



View Profile WWW Email
« Reply #3 on: February 01, 2013, 02:00:02 PM »

I just noticed a mistake of mine in the OP.  Obviously the difference between the horizontal/vertical and diagonal movement lengths using a square or diamond layout is actually the same, not different as I suggested.  Tongue

The diamond layout does look so much better though IMO as the diagonal movement in the x & y axis is less than in true horizontal or vertical movement and that's as it should be.
Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #4 on: February 01, 2013, 06:52:03 PM »

Quote
I just noticed a mistake of mine in the OP.  Obviously the difference between the horizontal/vertical and diagonal movement lengths using a square or diamond layout is actually the same, not different as I suggested.

Thats not right Fog.

They are different.

It's only the Hexagon shape where the distances are the same.  But that doesn't have horizontal movement (moving horizontally jumps a tile).

I've measured your images with a ruler and also created my own images in Paintshop Pro and both the Diamond And Square have different distances from tile center to tile center.

Personaly, i'd go with the standard square tile system myself, but use different distances to get to the neigbouring tile center.
I don't think it's an issue to be concerned about.

TMC
Logged
T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #5 on: February 02, 2013, 02:33:46 AM »

I created a couple of images to demonstrate the fact.

The 2d distance formula is

sqr ( (x2 - x1^) +  (y2 - y1^) )

or as i like to see it in long hand

dist_1 = (( x2 - x1 ) * ( x2 - x1 ))
dist_2 = (( y2 - y1 ) * ( y2 - y1 ))  
distance = Sqr( dist_1 + dist_2)

Image 1 (Square ) has coordinates

p1 = 0,0
p2 = 1,0
p3 = 1,1

Line X distance = 1
Line Y distance = 1
Line Z distance = 1.4



Image 2 (Diamond) has coordinates

p1 = 0,0
p2 = 2,0
p3 = 1,1

Line X distance = 2
Line Y distance = 1.4
Line Z distance = 1.4

In fact the tile shape is irrelevent as the distances are measured from the tile center coordinates.

TMC


* image_1.jpg (21.57 KB, 509x508 - viewed 267 times.)

* image_2.jpg (28.02 KB, 511x497 - viewed 261 times.)
« Last Edit: February 02, 2013, 02:39:15 AM by T_M_C » Logged
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13185



View Profile WWW Email
« Reply #6 on: February 03, 2013, 02:12:02 PM »

Quote
I just noticed a mistake of mine in the OP.  Obviously the difference between the horizontal/vertical and diagonal movement lengths using a square or diamond layout is actually the same, not different as I suggested.

Thats not right Fog.

They are different.
Slight miss communication on my part again it seems Smiley

What I mean was that the diamond pattern is essentially just the square grid rotated through 45 degs. so, assuming the squares and diamonds are the same size, the difference between their horiz/verts & diagonals is the same ( 1 vs 1.4 for on, 1.4 vs 1 the other )
Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #7 on: February 03, 2013, 05:45:02 PM »

Ahh ok.   Cheesy

TMC
Logged
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13185



View Profile WWW Email
« Reply #8 on: September 11, 2013, 01:22:35 PM »

Just stumbled across this on the subject of of grid based movement, tile shapes and sizes.  Rather than worrying about that, the guys who did Battle of the Bulge took a completely different approach and used non regular shapes and sizes.

Each "tile" representing how far you could move on that terrain,....so for example a tile containing roads would be big, whereas a tile complaining swamps would be very small.  It's obvious but rather clever.

There's a good interview here
Quote
I think that hexes are definitely associated with a certain type of game: lots of rules, lots of things to remember. Hexes kind of cause that. If you go with a hex grid, you’re dividing your map into all these equal segments – but not all terrain is made equally. If all your hexes are equal size, you have to make a series of terrain rules – how many movement points do you spend to cross a hex with a river? How many points to cross a hex in the rough? What about roads?

With area-based movement a lot of that goes away. If there’s a stretch of ground that’s easy to move across, you just make it a big area on the map.
Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #9 on: September 13, 2013, 10:28:27 AM »

Thats cool.

Always good to hear how other people solve particular problems.

You never stop learning.  Smiley

TMC
Logged
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13185



View Profile WWW Email
« Reply #10 on: September 13, 2013, 12:48:09 PM »

Thats cool.

Always good to hear how other people solve particular problems.

You never stop learning.  Smiley
indeed Smiley

It's a good example of coming at a problem from the exact opposite direction.  How many identical sized cells to move vs how big should each cell be.
Logged

Pages: [1] Go Up Print 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Simple Audio Video Embedder
Valid XHTML 1.0! Valid CSS!