PlaceholderGames / DinoPark-2017

repo for Dino Park 2017, the testbed for CS3S667
2 stars 0 forks source link

A* Path Search #23

Closed JakeP121 closed 6 years ago

JakeP121 commented 6 years ago

I've added an A* behaviour script that uses the map grid from issue #14 to plot the shortest possible route between two game objects.

I've also added a simple temporary AI agent that takes the path created from the A* script and follows it to show it in action.

The current implementation flags a Unity error when either the target or the AI agent are initially placed on unwalkable tiles, instead of starting/ending at the closest walkable tile. This could be improved on in future.

Available on branch 14734231.

JakeP121 commented 6 years ago

Branch now renamed AStar.

DoctorMikeReddy commented 6 years ago

Ok, I have recreated the A* stuff in master, but cannot set the Target for AI Path finder. I can set Goal but not Goal (Agent) as in the original. Any ideas? NOTE: The pathfinder still moves towards the goal but I get a Null exception because the Target does not appear to be referenced properly.

DoctorMikeReddy commented 6 years ago

Merged into master now, with a small issue about setting Target

DoctorMikeReddy commented 6 years ago

Thought I'd worked out why Target for me was Goal, where for Jake it was Goal (Agent) and showing a script icon, but I had added the Agent script to the Goal Object; however, it does not seem to see it as the correct type. No idea why this is, nor how the Node Type is set to PathNode (PathNode), as that is not an option that appears when you click the circle for selecting attributes. @JakeP121 can you look at islandAStar.unity on the main branch, and check all the correct scripts are there too, please.

DoctorMikeReddy commented 6 years ago

Update: I can set PathNode by dragging the prefab object from the relevant scripts folder. Still stumped by Goal (Agent) as the script is definitely attached, but not getting picked up

JakeP121 commented 6 years ago

I changed the Target from an Agent to a GameObject in commit 54905c6 on the AStar branch to add support for the script to find a path to any GameObject, that's probably why it's not showing up as Goal (Agent) anymore when setting it.

I should have mentioned that NodeType is set by dragging the PathNode script itself into slot in the inspector as opposed to setting it to an actual instantiated PathNode. This is because the A Star Search script creates a PathNode for each GridTile and needs a prefab to work off.

In my dissertation project I have done away with this method by creating a PathNode prefab in an 'Assets > Resources' folder and used Unity's Resources.Load() function to load it in directly rather than having to set the Node Type public variable for every instance. But this requires that 'Assets > Resources' folder that I didn't make in order to keep everything in my 14734231 file.

If you'd like I could create the folder and switch to this method to clean it up and make it easier for everyone using A star?

DoctorMikeReddy commented 6 years ago

Nah, now I know I'm not doing anything wrong, I won't worry. Thanks for the explanation @JakeP121