Return int(size.x + 1) * int(size.y + 1) * int(size.z + 1) We will need a function to get the total number of points: func total_size(size:Vector3) -> int: Skip calling int3 on the condition that the values you pass to vector_to_id are guaranteed to be integer.Store dimension_size(floor_size) and use that directly.
Return Vector3(int(vector.x), int(vector.y), int(vector.z))įunc dimension_size(size:Vector3) -> Vector3: Return int(int3(vector).dot(dimension_size(size)))įunc id_to_vector(id:int, size:Vector3) -> Vector3: Given that we have a floor_size, this is easy: func vector_to_id(vector:Vector3, size:Vector3) -> int: Let us establish a mapping between coordinates and point ids. To = aS.get_closest_point(rc.translation) # leftĭraw_connections(Vector3(rc.translation.x + 0.5,rc.translation.y,rc.translation.z + -0.5))įunc draw_points(): # Make points visibleįunc draw_connections(position): # Make connections visibleĬonvert between Coordinates and Point ids To = aS.get_closest_point(rc.translation) # rightĭraw_connections(Vector3(rc.translation.x,rc.translation.y,rc.translation.z + 0.5)) To = aS.get_closest_point(rc.translation) # backĭraw_connections(Vector3(rc.translation.x + -0.5,rc.translation.y,rc.translation.z)) Var to = aS.get_closest_point(rc.translation) # Frontĭraw_connections(Vector3(rc.translation.x + 0.5,rc.translation.y,rc.translation.z)) Rc.translation = Vector3(origin.x + value -1 ,0.5, origin.z + value2 -1) Var from = aS.get_closest_point(Vector3(origin.x + value ,0.5, origin.z + value2) ) # Current
If I could get a point using only Vector3 Coordinates, I think I could make it work.ĮXTRA: if you guys can show me a way to clean the code, especially on the "FORs" syntaxes, because I kind don't know what I'm doingĪny other clean code recommendations would be amazing and very much welcomedĪt the end has a visual draw(image) of the logic of the idea.įor _length in range (origin.x, origin.x + floor_size.x + 1):įor _width in range(origin.z, origin.z + floor_size.z):ĪS.add_point(i, Vector3(origin.x + value -1, 0.5, origin.z + value2 -1), 1.0)įor _u in range(origin.x, origin.x + floor_size.x + 1):įor _v in range(origin.z, origin.z + floor_size.z):
This is what I tried to do (obviously get_closest_point() is not working the way I wanted). I'm using a RaycastCast Node to detect the wall, and his position as it walk through every gridtileīut I can't figure it out a nested loop to find the neighbors points to connect
I figure it that out all alreadyīut I have no idea how to code how to connect the points in a easy way and not connect points that has walls in between. Instead of creating obstacles tiles, I'm creating walls in between the tiles, so the tiles are still walkable, you just cannot pass through a wall. I have a 3D gridmap node setup and I'm trying to autogenerate the dots and connections using A* Take the advice on the video to heart, gradstudent, you'll benefit from it immensely as a programmer.I'm trying to do something a little bit different then the usual. The developer of the engine agrees with this notion. So if you spend time optimizing it you spend time doing unnecessary work. That's not even to get into the main point, which is that you don't need to run the pathfinding algorithm every frame and that most of the time it actually isn't an issue. When you're building an engine that contains many moving parts you don't want to spend too much time optimizing each part to the best of your abilities because if you do that you'll never have a product that people can actually do something with. An inefficient solution works if it works well enough for enough people.
You're still not getting the point that the video I linked points towards, though. Gradstudent, I understand the implications of making the algorithm more efficient. By implementing the open list as an unsorted flat array, instead of a binary heap, its runtime changes to O(n^2). >Still not convinced? How about this: A* is supposed to run in O(n*log(n)).