Author Topic: [client + server] js ve mods pathfind - to cryofall c#scripts - rev1.123 STABLE  (Read 286 times)

ninekorn

  • Full Member
  • ***
  • Posts: 240
    • View Profile
sccspathfind => javascript void expanse mods pathfind to Cryofall c# mobs scripts RELEASED - rev 1.123 - STABLE [client + server]

rev1.123. i had made corrections to the dot product and somehow 0.45f using the dot product thinking it was close to 45 degree angle wasn't giving any good results, as the mob was trying to move at approx 45 degrees and the pathfind was resetting and the mob stopping. I fixed that. I also decided to separate the functions of the scripts sccspathfind.cs and sccspathfindactions.cs and put them in separate scripts to reduce the size of the scripts in kb as they were really high at over 90kb. (looking like this now it almost felt like i was just changing the names of functions and variables of the sebastian lague's pathfind tutorial on youtube. I understand you there. well it's years back thinking i could just name a function differently and add lots of things inside to fit my purpose and say it's my function now haha and then reference who i learned from which is pointless and ridiculous to name them differently but i wanted to release asap so i will see if i can rename some functions/scripts to try and stay true to the basic pathfind architecture and function naming of who i learned from). In order to do this, i had to create multiple scripts that do the same thing as rev1.122. but this time, the size in kb is much lower and it should help a tiny bit also for the performance during gameplay maybe. Also i cleaned the last unused using statements that i hadn't cleaned up in rev1.122.

Things i have developped differently or similarly:

1. negative/positive loops for inverted positive flatindex where supposedly flatindexing is faster than using multidimensional arrays, but sincerely using flatindexing after such a long time and never really testing/benchmarking if it's faster or not, i wouldn't be able to say if this pathfind project converted with multidimensional arrays would be better or not.
2. no check for list.contains. accessing everything by index only. I use arrays as i had done some tests way back and it felt as if accessing arrays were faster than lists or i was just using lists the wrong way. But i use 2d lists for the main pathfind data to be held within a script and i am unsure if that was a good approach but since i have to increase the size of the collection, i prefered to use a list. But i think using only lists will be something i will test also later, or dictionaries for the main lists in sccspathfindarrays.cs.
3. grid index retrieval using a spiral form of indexing if i can call it that, where i interpret the index as if when adding through a list is always added in a spiral form... And visualizing it that way, and doing trial and errors. And fetching the index in the spiral indexing of a list, only additions/substractions/multiples are required to fetch the index. no check for contains. no divisions. But my functions to fetch the grid index isn't perfect. far from it. I hadn't been able then to develop a fully customizable sizeable grid size. Also, i tried to approach the grid spiral indexing in 3d, and i am unsure how to approach that problem and tried and failed as of yet.
4. no multithreading, but useful since it's a per frame pathfind (not entirely per frame yet, because i still use 2d loops for checkallsides and for building a grid and for looping through the list of obstacles while building the grids) which aren't a per frame 2d flat loop which i will add later, and i also loop the neighboorlist entirely each frame so my pathfind isn't per frame per say yet.
5. linkable pathfind grids where it doesn't matter where the target would be in a map, what matters is, is the array/list that holds the pathfind nodes/openset/closedset/listofgrids will have enough memory available on the computer or maximum allowed memory allocated by the program? hence why i have put multiple switches and maximum allowed retracepath iterations, maximum allowed creation of grids. I will bring those variables in the sccspathfindglobals.cs the moment i release rev1.124.

I will work later on a sizeable pathfind grid if i can in my next revisions, where the nodes are smaller in size and where the pathfind is way more precise, and i will try to incorporate multithreading to have better pathfind results if i can. Also, small grids, don't make my pathfind technique better, it makes the process of pathfind smooth on the cpu where looping on too large grids can be a problem when big grids require big memory allocations, but that's how void expanse modding forced me to code like this. But looping a big grid of pathfind and having the target found on one grid, is something i couldn't do back then in void expanse modding which forced me to have to go through trying to develop my homemade pathfind project. There are still bugs. Try at the risk of losing players ranting because they die more often, otherwise if you try the pathfind project, i hope you like it.



I will stop posting many posts per day on the same projects. Only one if i really have a very decent update to the pathfind from now on. I have put my scripts in the folder "Scripts" so that the pathfind project is easy to drop into a mod that isn't already modifying the original Cryofall Mobs.  thank you for trying the project. I will try and set this up as a Cryofall mod for the steam workshop soon.



Repository:
https://github.com/ninekorn/sccspathfind2D-csharp

Path to the project:
https://github.com/ninekorn/sccspathfind2D-csharp/blob/main/Cryofall/stable

Pathfind exceptions:
Doesn't work yet on retreating mobs like chicken and starfish and others like those.
Doesn't work yet on boss mobs.
Doesn't work yet on some special mobs with abilities.

List of changes:
May 18, 2023, 01:32:37 pm » pathfind mod revision 1.05
2023-may-28 - 04:42:17 pm - RELEASE 1.063 - PATHFIND ON ALL SERVER+CLIENT MOBS. SCRIPTS INCLUDED FOR MOBS AND PATHFIND.
EDIT2023MAY28-20h11-BUG FIX: there was an annoying bug where mobs that the player had never seen before, were moving away from the player when the player was seeing them for the first time. Bug fixed. The player was null so the mob was aimlessly going wherever. REV 1.063
2023-may-29- released revision 1.1 stable. Pathfind for all mobs with exceptions. Rev 1.1 released now stable. now the pathfind is individually taken care of by my scripts and there shouldn't be any entertwining of the path in memory between any mobs anymore. This is approx my approach that i did for void expanse modding player drones back then but i never had done it for the entire server enemies before. I hope you guys enjoy it. next step in development maybe, is making it better, cleaner, and adding different settings for the different mobs as currently they all act the same way with the pathfind. The npc pathfind path currently is slow to refresh a new path. i know and i will work on improving/tweaking that part and it shouldn't affect much  the performance by making the npc try to discover a new path faster. Multiple settings are available to choose from to decide how many times per frame should the pathfind launch and a lot of other settings. I will work tomorrow on giving a better description as i am tired and need to go sleep.
2023-may-29-release rev1.11 - Rev1.11 released . The pathfind path for each Cryofall npc now restarts faster to get a new path, if the npc is heading away from the character when already moving through a path. which in turns makes the npcs more aggressive as they are getting closer to the player faster. Also i have cleaned up the mobs scripts, and moved the pathfind action logic into a new script sccspathfindaction.cs so that it's easier to work with instead of pasting all of it in the mobs scripts everytime that i do a single modification.
2023-may-29-release rev1.12
2023-may-29 - at 11:22:00 pm - 1.122.
2023-may-30-release rev1.123

developed by steve chassé aka ninekorn
« Last Edit: Today at 08:46:07 am by ninekorn »

ninekorn

  • Full Member
  • ***
  • Posts: 240
    • View Profile
Rev1.122 released. I added global lists per type of mob for better memory partition (wolfs and boar and hyenas and bear and all other npcs have their pathfind data in their own respective lists in sccspathfindarrays.cs). I also had cleaned up the too many using statements i had added in all of the mobs scripts since i had created sccspathfindaction i hadn't removed them. In my earlier releases, all mobs were inside of one big list. Now it's one list per type of mob so a total of 26 + 1 lists for the original game type of mobs.

Rev1.121 released. I added global variables in the script sccspathfindglobals, for collision check or not while npc is moving, for retreat/stabilize npc on pathend or not, for type of node sort for each npc. Check script sccspathfindarrays.cs for sorting nodes pathfind options per mob type. I have modified the movement speed of multiple npcs. Wolf/boar/bear/hyena and some other minions are now using FCOST "best shortest path to the target" for the path discovery which takes a tiny bit longer to process since the pathfind tries mostly all routes nodes based on the Gcost and Hcost so that all nodes that always represent the shortest path are discovered first and in the end it is possible to retrieve the best shortest path but it takes longer to discover more nodes. Other npcs are using HCOST for "fastest path to the target" which is faster to process but in a labyrinth FCOST would be better than HCOST dependant on if no other settings are added for the hcost as it is so fast to find a short path in an environment like a jungle/forest where there are no big obstacles to go around except ingame player constructions and abandonned ingame lab sites. Let's test it this way and see if it is liked or not. Mobs are harder this way, the CryoFall worlds feels less a secure place now. But there aren't any logic implemented yet for when a mob is nearing a player base, so don't expect the AI to be that smart either for the moment just because it has pathfind. It won't change that the AI will still collide with many things without more logic added to this, and it's not coded perfectly yet so i don't understand why the npc collides with some trees as if it never found a collider there. i will investigate.

Rev1.12 released. The aggro is now different per mob types with distance settings in the script sccspathfindarrays.cs. Also i reduced the variables "pathfindimax" and "retracedpathlistcountermaxloo p" to 1, since it was lagging with not a lot of mobs but it was due to the many calls i was doing to "physics.castline" to find physics colliders so i also commented out half of the logic from the function "checkforobstaclesontheway" in the script sccspathfindaction.cs. I was checking for collisions from the direction of the npc and direction towards the next node, but also i was checking the direction of npc and direction towards the player. Currently i decided to rely only on the direction of the npc towards the next node obstacles check. So currently, higher settings might make your servers lag if you use my pathfind mod if you put "pathfindimax" and "retracedpathlistcountermaxloo p" higher than 1. If you don't care about mobs colliding more often with obstacles, than you can comment the line that calls "checkforobstaclesontheway" in the script sccspathfindaction.cs and that should make the gameplay even smoother. Also, i fixed the rotation of the npc where, when there was no players, the rotation in radians was becoming null and at every movement of the character the npcs were rotating in a random rotation... Also i fixed the npc movement when moving towards a character the animation wasn't playing and that was due to not using "ProcessAgressiveAi" or "ProcessRetreatingAi" but only updating the direction of the movement server-wise with ServerSetMobInput, so i learned that those 2 functions "ProcessAgressiveAi" and "ProcessRetreatingAi" are internally also applying animation frames or something. This is my last "burst" update, for the moment, as i think now the pathfind feels stable and smooth, although the mobs are still colliding with the world gameobjects, and that the npcs are stopping after reaching the end of the pathfind path everytime. I haven't tested with any players ingame in multiplayer. I only tested my scripts with a couple of mobs max 5 mobs but the pathfind is activated on all mobs on the server (minus the exceptions below).


revision 1.05 - May 18, 2023, 01:32:37 pm » pathfind mod

hey everyone. I have been working on retranslating my void expanse mods pathfind development to c# and i have some good results. I wanted to share them with the community until i develop a functional Cryofall mod where i would use my c# pathfind development. Currently my revision works in Unity and i made sure to not vary much the code from my development of void expanse mods, and i did try and remove the abreviations i was using for variable names to "encrypt" my scripts manually.





I have decided to release my c# pathfind development with the apache license 2.0, and decided to share my development to help with Cryofall mods. If i can successfully or not incorporate my c# pathfind development into Cryofall, which i should be able to if i start learning the cryofall c# API soon, doesn't matter anymore as i have finally released it and with the apache license 2.0 which is very permissive, so that others in the community might like my approach and use my pathfind "library/scripts" although Sebastian Lagues pathfind and other libraries are also great. Basically as far as i understand, the Apache License 2.0 all sums up to referencing my name and work (including the work of others i reference in my own work) if you use my copies in other softwares you distribute or something close to that. I am unsure if this license choice was the right license to choose though, but i read on the internet it can protect a patent better, as i have not plagiarized my creation, and that it is compatible with the MIT license. I did use as reference the knowledge and a little bit of the code as reference from Sebastian Lague's pathfind tutorial on youtube (hosted on github.com MIT licensed), but not all of the code as linking grids together is something i developed on my own and fetching the index of grids in spiral is something i developed on my own and using premade arrays of unwalkable tiles and use the index is something i developed on my own, i didn't use as reference more than 1-2 episodes of Sebastian Lague's youtube pathfind tutorial which had helped me finally understand pathfinding in programming. Don't believe me? read my code, as this is a direct translation of my void expanse mod pathfind from javascript ecmascript5 to c# and i tried to be the most truthful i could be of my own development in my mods for void expanse for this c# translation. And i repeat, the architecture of how pathfind works, is very well explained in the first tutorial of pathfind of sebastian lague on youtube, and i use quite the hierarchy explained in the first video of the tutorial of sebastian lague. And unfortunately in the beginning my goal was to do a perfect translation of Sebastian Lagues pathfind tutorial on youtube to javascript ecmascript 5 strict mode, but i didn't have multithreading, i didn't have pathfind visible path, i didn't have anything. So i had to develop an alternative solution to reduce the weight of the pathfind for each script/drone that would use the script in my void expanse mods. Now, i have finally translated that work from javascript ecmascript5 to c#. Currently, i only made the pathfind work for the station exterior outpost, models that i had built for use in void expanse mods. I do not know how fast it fares against other pathfind techniques though. But currently my revision is not multithreaded and it is not using compute shaders for faster pathfind calculations. But no, i am not developing a void expanse game in unity. What i am doing was translating my pathfind from my void expanse mods in javascript ecmascript5, to c#, in order to use my pathfind for cryofall c# modding among using it with my own c# personal projects.

But please note that i have a lot of work left to do on adding every reference to others work including references from my own work that i move left and right everywhere in the projects that i make. I will try and work on that soon.

Controls:
movements W-A-S-D and SPACE to stop

The debug.drawline is for the editor view, and this is a draft/wip project and it had to work, not be a game. The goal was to make my javascript pathfind work in c#.

download link:
https://github.com/ninekorn/sccspathfind

my original void expanse pathfind/drone/galaxymarket mod post is here:
https://forums.atomictorch.com/index.php?topic=1361.0

steve chassé aka ninekorn


« Last Edit: Yesterday at 11:46:35 am by ninekorn »

ninekorn

  • Full Member
  • ***
  • Posts: 240
    • View Profile
bump. release 1.1 STABLE.

ninekorn

  • Full Member
  • ***
  • Posts: 240
    • View Profile
2023may29 - at 08:28:04 am - bump. release 1.11 STABLE.
2023may29 - at 07:19:00 pm - bump. release 1.121 STABLE.
2023may29 - at 11:22:00 pm - bump. release 1.122 STABLE.
« Last Edit: May 29, 2023, 08:22:53 pm by ninekorn »

ninekorn

  • Full Member
  • ***
  • Posts: 240
    • View Profile
2023may30 - at 10:08:04am - bump. release 1.123 STABLE.