The Start of Pathfinding! (Ongoing Project)

Hello everyone,

I know many people have been trying to make games with pathfinding, and I created a project that may be used to eventually, make a pathfinding game with an entity and a player.

This is the shared project:

Right now, there is only room detection with the game knowing exactly where everything is, but we can simply add path points to tell the entity to move depending on the room the entity and the player is in. The only problem with this, though, is that it would just be too much to just add an “if” block for every single possible combination of the current room positions. Is there anyone who has a better way to tell the entity to move instead of adding tens of “if” blocks?

Thanks!

10 Likes

Good idea @Bladebob20000 - this will be useful for indoor spaces. Here’s my contribution - a simplification of the collision code: CoSpaces Edu :: Remix of Pathfinding v1.1 (room detection) demo

What’s your next step?

5 Likes

Hi @techleapnz and to the community!

I have really scratched my head about this, and my final ideas were;
this idea can branch off in two ways. One involves making the AI move in a one-way direction depending on which room the AI is currently in. This method was inspired by a scratch pathfinding tutorial, and I think we could be able to make a similar version on cospaces. However, this would create complications for the game as it will only allow the AI to move in one way, and would not be able to go to a specific updated point. (If anyone has an idea of how to guide the “one way” to make it move towards an updated spot, such as the player, please let me know). The second method will involve moving the AI across random rooms in the guided path (this can be randomized with a random number block) and making the AI look toward you and chase you when the room number and the player number match, seeing that will mean you and the AI is within sight.

In conclusion, none of these methods I mentioned is a direct solution to pathfinding, and will not work for people looking for ways to make a perfect pathfinding AI or entity travel to the player with the shortest route. As always, I am always looking for any ideas that can be an alternative solution to this and I encourage all of you all to make a post for anything that can be a potential contribution to this idea that has been though of for months, maybe years. Thanks!

Link to pathfinding tutorial for scratch (basically cospaces on a 2d engine):

PS: (I’m working on remixable projects for the methods I mentioned above, I’ll probably be finished in a few days or more)

7 Likes

Hi, I had already worked on it successful in the past and I think we can create something like that in CoSpaces, I will work on it in this afternoon (Italian time zone). Hope also @techleapnz or another expert of CoSpaces will work on it

5 Likes

Hello, I worked about pathfinding and I think I reach the best solution for an AI that moves through some rooms.
But unfortunaly the system doesn’t work probably because the collisions commands in the function doesn’t run, anyone have the solution of this problem?

This is my project:

However, the system consists in making a fuzione that moves four cubes in two directions and two lines of x and y (simply forward, backward, right and left), the last of the cubes to reach an element of the group “walls” will be the direction towards which the main element will move and then restart the function repeating the whole, maybe solved the problem of collisions you could work on counteracting the inevitable loops that will create (perhaps by keeping track of the path taken by the main element using another function).

6 Likes

I think we are already at a good point, let’s see what @techleapnz thinks.

5 Likes

Hi team, I think we need to be very clear about the scope of the pathfinding:

  1. Are we wanting to build a 2D pathfinding system for a maze-like environment (like in the Scratch tutorial), or a 3D path-finding system that works in any environment?

  2. Does the pathfinding system have to behave in the same way as the Scratch system, or can we use alternative means (such as following the Camera)?

  3. Is it for a single entity or multiple?

  4. Should the path-finding start straight away or be triggered by “seeing” an entity?

It’s easy to create something that fulfills some criteria, but difficult to create something that looks really good.

5 Likes

@techleapnz I think this idea if fixed could be used in all ways (2D and 3D adding two more cubes).
For the other things let’s see what @Bladebob20000 thinks.

4 Likes

I hope you’re having a great day @techleapnz!

Yes, sorry I haven’t been clear on this. First, my goal for this project is to create a way for a single entity to pathfind to the player. I am thinking of this as a 3d environment, so less experienced builders can make their own projects or game with a simple pathfinding template. And, to clarify, I used the scratch tutorial to create an example of an alternative similar way for the entity to move. For your fourth question, this honestly depends on what project someone is trying to make, but I think sticking to straight-away pathfinding will be much easier to understand and we can always adapt afterward. Here is an example of a game I imagine to be able to create if we finish this project; There could be an escape room “horror” game where an entity will chase the player (if possible, maybe multiple elevated environments such as a two-story house?) around the map and the player must solve puzzles to escape while at the same time avoiding the enemy. That’s all I have on my criteria for now!

Thanks!

5 Likes

I’m pretty busy at the moment, but if I have a moment, I’ll have a go at trying a couple of pathfinding options.

So, @Alessio_Bonini, I like your idea - so the chaser sends out cubes (like sonar) to navigate the world. This currently assumes a perfectly square grid maze. To solve this, we could create a single function to send out a block to scan the world in a single direction, then do that in all directions, make a note of 1st collision position, and send the chaser to the position.

This way is teach the AI to find it’s own way to get to the player; the Scratch way is to tell the AI where to go.

4 Likes

Hi! I would like an update on this project, did anyone find something yet? @Alessio_Bonini @techleapnz

4 Likes

Actually we are at the same point. If you want you can contribute to create this project, just read the topic and try to create a CoSpaces project qoth them and your abilites.

3 Likes

@techleapnz @Alessio_Bonini @Bladebob20000 I have made a mockup A* algorithm, quite a fun challenge since I had not made any algortihms before. Also trying to code it in coblocks, following a Python tutorial while my only programming experience is in C++ and even that is neglectable.
Anyhow thats long to say it was quite an adventure, however once understood the A* algorithm is suprisingly easy to follow as it really does not make any difficult calculations or leaps of knowledge… its like a very smart baby… sort of.
Currently its far from perfect, its a bit clunky but it certainly works. I have added visuals (and time delays) so that you can visually follow what the program is doing. I will add some more comments in the code to explain the steps and make a better visual version and ofcourse one without; Which should calculate quite fast.
Would love to hear what you guys think!

4 Likes

Also @techleapnz maybe you can help with this one if I use the for loop indicated in the red outline, instead of my searchLowestF function to search for its lowest F or if they are the same the one with the lowest H value.
However for some reason it checks the 160 grid as the first at the start but im not sure why, its problably a off by one error but I cant seem to wrap my head around it… all i have found is that that node is the first one it calculates and thus adds to the list… but it clearly does not have the lowest f value (Visually, f is the big one in the middle, g score is top left and h score top right, in the vector x=g, y=h, z=f).

4 Likes

Here’s the stripped version, It’s actually faster than I’d imagined.

5 Likes

Wow this seems to work so well, tomorrow i will study the code and try to improve it (it is already very good in my opinion with also the visual version).

5 Likes

Also made a little maze for it, its fun to see how it tries to figure it out.

5 Likes

Very cool, it has a lot of possible application.

4 Likes

Thanks @Alessio_Bonini curious to see what you do with it, also do share if you do some tests with maze / walls i think its very intresting to see how the algorithm deals with the different situations.

4 Likes

Yes of course, first i will try to apply it in my pac man game for the ghosts.

3 Likes