• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ivansla

Movement animation in hexagon map

8 posts in this topic

Hi guys!

I'm trying to create a hexmap based game, like Panzer General, well actually I'm trying to animate unit movement.
And this is where I have problem. I am using A* algorithm to determine the path, so that is not problem.
My problem is that image I'm animating is always a couple of pixels on X-axis late.

This is how I calculate the movement:
[code]

int SPEED = 1;
int SOUTH_EAST = 300;

double newX = Math.cos(Math.toRadians(SOUTH_EAST));
double newY = Math.sin(Math.toRadians(SOUTH_EAST));
this.speedX = SPEED * newX;
this.speedY = -SPEED * newY;
....
// later in code inside each frame
this.x += this.speedX;
this.y += this.speedY

// drawing of image inside each frame
g.drawImage(this.tileImage, (int) this.x, (int) this.y, (int) this.x + TILE_SIZE, (int) this.y + TILE_SIZE, frameX, frameY, frameX + TILE_SIZE, frameY + TILE_SIZE, observer);
[/code]

The problem is that those 300 degrees is from 0,0 to 39,39 (My tile size is 40) which is diagonal of the square inside which the hexagon is, and I need a little sharper angle since I'm not working with squares but hexagons. Ok, I know I need to provide correction for x and y, but that is not the point, point is that my movement by X-axis is late and if I put the angle of 305 that is too much.

Well my question is, how am I suppose to animate the unit movement from one hextile to another?
Is my approach good and I just need to do a better math calculation (I'm terrible in math, BTW) or is there some other approach?
0

Share this post


Link to post
Share on other sites
Hi,
I'm trying to visualise your problem, but I'm failing at it [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
How is your hex grid oriented? Do the hexes form straight rows (x axis) or columns (y axis)? How do you measure the angle 300?
A little simple picture would help a lot.

Tom
0

Share this post


Link to post
Share on other sites
Hi Tom, thanks for the reply.
Here's the picture you asked.
[img]http://uploads.gamedev5.net/gallery/album_392/gallery_196065_392_2344.png[/img]

I imagine there is a circle inside the hexagon. and since all the sides are the same I just divide 360 / 6. and I get 60 degrees for each direction.
0

Share this post


Link to post
Share on other sites
The angle -60 (or 300) should be absolutely fine and accurate.

You say the movement is behind only on the x axis? It reaches a point located left of the desired target point? I really cannot imagine how would that happen. Is the grid drawn properly, isn't the problem actually with how the grid looks and not with the movement?

Or, is it possible to make some screenshot of the exact problem you are getting?
0

Share this post


Link to post
Share on other sites
Ok, Tom, for better visualization, I decided to upload my project. it contains source as well it's in Java, if you just want to run it, you can do it by double clicking.
[url="https://rapidshare.com/files/1778542098/hex-tutorial-src.jar"]http://rapidshare.com/files/1778542098/hex-tutorial-src.jar[/url].

As you can see, the tank is not inside in exact hex tile, but is out of bounds. and the lower it get the bigger error it has.
0

Share this post


Link to post
Share on other sites
The hexes definitely aren't rendered properly, they are stretched - they are too wide. You cannot draw an inscribed or circumscribed circle in/around the hex.

I think the tank moves properly (it seems so but it's hard to tell), but the displayed hex grid doesn't correspond to it, the tiles are too short vertically, thus the tank ends far away below.

EDIT:
When I'm examining your grid more, I think I know what you did wrong. It seems that you misunderstood how a hex should look like.
Check the picture, left side shows how it should look, right side is your case.
Drawn in red is an inscribed circle and in green a square - you managed to fit your hex into a square, but that's not right ;)

[url="http://www.freeimagehosting.net/xz5x9"]http://www.freeimagehosting.net/xz5x9[/url]
0

Share this post


Link to post
Share on other sites
Yes, Tom you are correct, I did it the way showed on the right side.
When I was reading following articles:
[url="http://www.gamedev.net/page/resources/_/technical/game-programming/isometric-n-hexagonal-maps-part-i-r747"]http://www.gamedev.n...aps-part-i-r747[/url]
[url="http://www.gamedev.net/page/resources/_/technical/game-programming/coordinates-in-hexagon-based-tile-maps-r1800"]http://www.gamedev.n...tile-maps-r1800[/url]

I got the impression that's how it's suppose to be. Especially the second one.

So, in order to fix my problem, I need to draw smaller tank or draw different hexes? Because my hexes are 40x40 px.
I thought that when I draw a hex into square, the hex will have all sides the same. In your case certain sides of the hex are bigger than others.
0

Share this post


Link to post
Share on other sites
Ok I found this article: [url="http://gdreflections.com/2011/02/hexagonal-grid-math.html"]http://gdreflections.com/2011/02/hexagonal-grid-math.html[/url].
So Tom, thanks for showing me my error. Since I have poor mathematical background no wonder.
I will try to redraw the hexes.
0

Share this post


Link to post
Share on other sites
I'm glad I could help. Please let me know when you get it working right, or feel free to ask should you have any further questions/problems.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0