Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Troubles with A*

Hello. I'm using Cowlol's A* Pathfinding Script (click) but have had some troubles with it. Here is the code I used:
Code:
char = 46

x = 13

y = 25

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Code:
char = 46

x = 13

y = 16

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Code:
char = 46

x = 20

y = 14

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Code:
char = 46

x = 13

y = 25

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Code:
char = 46

x = 28

y = 25

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Code:
char = 46

x = 28

y = 29

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Code:
char = 46

x = 1

y = 25

goal_node = Node.new(x, y)

path = A_Star_Pathfinder.new

(goal_node)
Each code tag represents a script call, all in one parallel process event. In game, though, the specified event doesn't move. I know this isn't a problem with the map- I tried it using the Move Route event command and it worked- so what am I doing wrong with A*?
 
Error.png

I get that error when I try it that way. Here's the code I used:
Code:
node = Node.new(13, 25)

char = $game_map_events[46]

path = A_Star_Pathfinder.new(node, 

char, false)

path.generate_path
 
You copied it wrong, it's $game_map.events[46], not $game_map_events[46]. Though it's not necessary to pass an event (it can figure it out if you give it a number).

This is a more compact version of SephirothSpawn's code that you can try (hopefully you won't confuse . with _ this time :wink:)

Code:
node = Node.new(13, 25)

char = 46

path = A_Star_Pathfinder.new(node, char)

 

I'd like to note that pathfinding takes a lot of processing (i.e. slows down your game) and it's generally not a wise idea in a parallel process. One of the examples in the pathfinding demo does this to simulate a caterpillar system but that was mainly to show certain features of the script, rather than the right way to do it.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top