Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A* trouble  (Read 466 times)
0 Members and 1 Guest are viewing this topic.
Offline Sabomoth

Junior Member


Medals: 1
Exp: 2 years



« Posted 2014-03-15 15:30:45 »

I am having some troubles getting my A* algorithm working correctly, or rather, implementing the path on my entities correctly.

I have successfully implemented this code into my game, it gets a path that avoids mountains and lakes.
http://www.cokeandcode.com/main/tutorials/path-finding/


The problem starts when i want my entity to follow the path. My map is made out of 8x8 tiles, and the algorithm calculates the path according to the map array, which makes the path 512x512 pixels large, instead of 512x512 tiles large.
This creates a problem;
I am not able to create a path to anything outside a 512x512 pixel area on the map, since otherwise it would be out of bounds, i have tried to fix this problem, but dunno if its a correct way.
The unit does follow the path correctly, if i paint the path up, and then enlarge it over the map it is correct.

I have tried to fix the problem by making the algorithm to work with tiles by dividing the target x/y by 8, thus getting the position in tiles. Doing this f*cked it up though, so probably i have missed something somewhere.  But my question is, is this the right way of doing it? The point is that i also want the units to walk pixel by pixel, but the a*star guides i have seen all goes by tiles, i dont think making a gigantihumongous array with every pixel on the map is a sane way of doing that.

The game i am trying to make is RTS, but the only tile based stuff on it is the map, think age of empires.
Offline Gibbo3771
« Reply #1 - Posted 2014-03-15 17:03:20 »


The point is that i also want the units to walk pixel by pixel, but the a*star guides i have seen all goes by tiles, i dont think making a gigantihumongous array with every pixel on the map is a sane way of doing that.

The game i am trying to make is RTS, but the only tile based stuff on it is the map, think age of empires.

I am just starting to learn A* however I can tell you right now that sounds like a stupid idea, get a unit system sorted.

You should have something like tiles, cells etc etc. How are you even loading in a map if you have no measurement system?

For instance, for my implementation I am loading tiles using an image and it's pixel values, each tile is 1 unit by 1 unit, so 1x1 meter. This allows me to have each node take up 0.25m for precision.

If you have a coordinate system, you should not have the problem you are describing. (I think, that could just me being new to A*)

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Sabomoth

Junior Member


Medals: 1
Exp: 2 years



« Reply #2 - Posted 2014-03-15 23:12:02 »

Like i said, the map is created out of an array, which decides what tiles go where.
The problem arises when the tile array, lets say its 512x512 tiles large, which makes the map 512x512x8 pixels large.
One problem is that the algorithm has problems when going between the two, the second is the bad movement, the entity going to the "0,0 position" on each tile.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline UprightPath
« Reply #3 - Posted 2014-03-16 13:58:20 »

This sounds like it's an issue of mapping rather than an issue with your path finder. If your system is already able to find the 'Correct' paths than you should be good.

What you should look into is a good mapping/movement function. By this, I mean that you should have some sort of function that maps from tile space to screen space. It sounds like you already have one for when you're drawing your tiles. That said, you probably also need some sort of 'between tiles' movement function. Basically, you use the tile-to-pixel mapping function to figure out where an object should appear on the screen when it's on a certain tile. And the movement function would be a time-based function that moves the object between those tiles in a smooth manner.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (69 views)
2014-08-11 02:49:23

BurntPizza (46 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!