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.
Yes of course I will optimaze the code to make it not lag. Thank you for tour advice about optimization.
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.
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!
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.
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?
It could be because an element canāt be the first element of a collision event more than one time. Hope this advice helps.
E quindi aggiungiamo per sempre ? Che ne dici @Alessio_Bonini come mi aveva suggerito @miccoro
Dovrei vedere il codice, io crerei un evento collisione per ogni spazio con lāuscita come primo elemento e il giocatore come secondo essenzialmente.
Ho risolto Alessio posterĆ² il codice appena possibile.
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!
@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!
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;
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?
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.
@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)
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)
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
Curious to see what you will create!
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?
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