The Start of Pathfinding! (Ongoing Project)

I would recommend using a preset grid for that, instead of calculating a new grid each time.
And possibly setting the walls at the start of the game.

3 Likes

Yes of course I will optimaze the code to make it not lag. Thank you for tour advice about optimization.

2 Likes

And another maze, without visuals. Its really fun to play around with actually haha. Will make a better/ faster sorting system next week and possibly have the visuals be a switch so you can see both results within the same cospace.

3 Likes

Well done @Luc ! I look forward to having some time to check out your solution! Great to see all the collaboration and cross-pollination of ideas going on!

4 Likes

Thanks @techleapnz in the end I settled on this version CoSpaces Edu :: Pathfinding in Coblocks (A* Algorithm)
I ended up making one using a heap sort aswell which I posted under another topic; Unfortunaly lag spikes when calculating seem to be inevitable using a system like this; making me think an adapted version of @Bladebob20000 's original idea would work better.

3 Likes

Hi Comunity, I took a look at your solutions because I have a simular problem. We are creating an escape room in a monastery with more than 7 spaces.
We would like that every single space has is own music or sound.
I noticed a trigger canā€™t be a group of elements but just only one adapted cubiod in trigger.
The block collision with the exit doesnā€™t work when you have more than two spaces.
@Claudio_Pacchiega and @miccoro tried to help me but this becomes more complicated when you have more spaces why?

2 Likes

It could be because an element canā€™t be the first element of a collision event more than one time. Hope this advice helps.

4 Likes

E quindi aggiungiamo per sempre ? Che ne dici @Alessio_Bonini come mi aveva suggerito @miccoro

2 Likes

Dovrei vedere il codice, io crerei un evento collisione per ogni spazio con lā€™uscita come primo elemento e il giocatore come secondo essenzialmente.

2 Likes

Ho risolto Alessio posterĆ² il codice appena possibile.

3 Likes

Hello people! I was reading this forum and remixed a few of the version. It amazes me how you can think and code like this, but since I am not good enough to even understand the code. Can someone roughly explain to me what function does what.
Thank you!

4 Likes

@TMS2024_Luka Hey Luka, this version has an explanation of the algorithm when you press on the explanation button while playing.

Iā€™ve also added all of those steps into the code as ā€œCommentsā€; These are blocks of code that do nothing but are a way to insert text into parts of the code. Iā€™ve indicated my comments by using an empty block (seen as []) before each explantion, By clicking on the block with text in it and moving through it with the arrow keys or using the scroll wheel, youā€™ll be able to read the explanation of the code.
Hope this helps, if you have further questions you can send me a message, Iā€™ll be glad to help!

4 Likes

Small update: After having gone through much trial and error on multiple attempts, Iā€™ve opted for a much less of a pathfinding and more of a ā€œletā€™s try to walk around what is in front of usā€ -approach.

This is also the approach used by coSpaces themselves in their ā€œMarble maze gameā€, there however the enemy is restricted to 90 degree turns only, and does not actively search for the player which works very well for their game specifically;

My version tries itā€™s best to make the enemy walk around an object if it were to encounter it. Itā€™s movement system is just rotating towards the target, and walking forward on a loop; Then if it encounters an item designated as physicalProp it rotates 90 degrees in the direction closest to the target.

Logically this results in the enemy continuing itā€™s movement by looking back at the target, moving forward and then hitting the wall at the exact same location it has done before, to counter act this I added a buffering system that stops that rotation from happening while the bufferTime after the wall has been hit has not yet elapsed and, hitting a wall in the mean time resets this timer.

Now another problem is encountered as the enemy will simply look left/right continuously as the shortest direction will oscillate when moving around an object if the player is right behind it. So using the formentioned buffer time Iā€™ve implemented a short memory that remembers the original shortest direction, and uses this direction instead of the current shortest one while its buffer time has not yet elapsed.

All in all itā€™s far from optimal as youā€™ll see it fares relatively well in open spaces with free standing objects blocking itsā€™s path, but struggles once it gets to confined spaces; Even so I figured somebody might still find use for it;

4 Likes

Nice Job @Luc!!!

This project is really amazing, and the code was really clever. This method could work well in many platformers or more simple pathfinding games. However, I found bug in the project which if the entity is inside the small maze part of the map and the cube right outside, the entity sometimes just go through the wall. Is there a way to fix this?

2 Likes

Thank you @Bladebob20000, unfortunately I cant seem to stop that from happening; The system does not work great within closely confined spaces more so oriented towards individual blockades.

2 Likes

@Alessio_Bonini @Bladebob20000 @techleapnz Iā€™ve gotten around to making the algorithm using Typescript, it has a noteable performance boost, this whilst not even using a heapsort for the nodes yet; Which might help boost preformance further (in Unity using C# this managed to increase its speed by x4), Iā€™ll probably implement this sometime in the future to see how much itā€™ll actually end up helping.

Though there is a clear lag spike when the grid is being created due to initializing all of the collision events (for which Iā€™ve assigned 1 second, after which the event is discarded & for the Optimized version the tile deleted), the algorithm might actually be fast & lag free enough to be used for small games, while currently the seeker finds a new path every 0.3 seconds, this can be reduced if lag persists.

Hope it will be of use/interest to somebody, eitherway it was quite fun to make (and ultimately only took a day of frantically googelling how to write in typescript).

(Base Version)

(Tile-less optimized version)

(Maze Example, Scene 1 is with visuals, Scene 2 without)

6 Likes

Amazing job Luc!!!

(I had some things going on so I couldnā€™t be active on cospaces for a while)
This would be the answer into creating a single floor pathfinding game!
Iā€™m not much of a typescript person myself, but is it possible to run the same pathfinding for elevated or custom floors that differ from the rest of the terrain? (For example, a small platform or possible another floor to a house)

4 Likes

Thank you @Bladebob20000, running multiple floors without connection is certainly possible, meaning the pathfinding enemies would be locked to their floor; Or a very cheatsy way of making them change floors, would be to teleport them to the nearest tile on the floor of the player, if the player has moved floors.

Connecting them however (through stairs) seems difficult, and take in mind Iā€™ve not yet implemented this anywhere including in Unity, but my educated guess is that it would too hacky/ difficult to get it done in coSpaces.

Also unfortunatly my pro-license has expired meaning I can no longer access the code to my CoSpaces, that being said Iā€™d be happy to try and help you along, but might require either clear screenshots or just copy/pasted code of the parts that you would be strugling with, as I do not know the code perfectly from the top of my head :sweat_smile:

Curious to see what you will create!

2 Likes

By the way, what item did you use to make your ā€œWallPropā€? And, why is the WallProp necessary for the pathfinding when you can just have the ā€œfalseā€ walkable grid tiles be the ones that the actual obstacle is touching?

2 Likes

Your right in assuming WallProp is not nessecary, its just an invisuble cube but the object does not matter; Its the name I use to reference wether an object is a wall or not.
The problem of not using it is that ANY object will trigger the grid to think it is a wall, including the player and enemy themselves

2 Likes