0 votes

This is how my code looks right now. It does'nt work at all.
I have a simple pathfinding system that says:
Is it my turn? if yes;
am i NOT next to the players pos and do i have "movement" left? if yes;

the "enemyalternativeroute()" func leads to the above mentioned code:

which has an IF or ELIF statement for each four directions (only working on 1 for now, for testing)
Here i make it move it's directional raycasts in an alternative direction (up/down instead of left in this case) and see if it will collide with anything if it tries moving (left) from there, and if so start moving towards that point instead.
This would allow it to overcome 1 "tile" worth of obstacles and i would be able to expand this formula up to any number of tiles.. i think.

But this doesn't work, it moves the raycast and it obviusly collides with the obstacle, yet it prints "false" when i ask if it has collided, and as such only takes the "north" direction and never the "south" even if the path is shorter.

I bet there is a much simpler way to do this... If so, I would LOVE to hear it.
Navmesh or polygoninstance and nav2d takes the corners and not the centers of my tiles, so I can't make that work either. (Tiles are 50x50pixels atm)

Any help is appreciated and congratz if you actually read all this nonsense and made sense of it :)

in Engine by (33 points)

I don't get what you mean by "Navigation2D takes the corners and not the centers", because that's actually the thing you need, as well as a Tilemap if you use tiles.

Wow yeah reading back again that was horribly worded.
As i've come to understand Navigation 2d, from "Gamesfromscratch"? maybe?, it takes the absolute shortest route, meaning if I made a polygon of the walkable area, the navigation would cut corners near obstacles. It wouldn't move my node through each tile's center, onto the next and so on but rather move through the entire walkable area with the shortest confirmed route.
^from a video explaining 2d nav (https://www.youtube.com/watch?v=b7rhFPcj230)
It does seem to take into account the size of the node moving around nor the size of the "hallways", rather just whatever point to point path is easiest.
I hope that made more sense

I understand the size of the node may not be taken into account. There are several ways of dealing with that:
- Run your own machinery so you can process the path in order to make it pass through closest waypoints allowing your node to pass through them (so running raycasts along the path points to adjust its positions toward walls)
- Have another layer where colliders are bigger (but ignored for physical objects) so the path will be generated as if it had to pass through narrower areas, forcing the path to not cut the real corners
- Manually place waypoints on your map and use the AStar utility class

I didn't investigated a lot about this issue but you can do those things to improve path computation. I don't remember having this problem that much when testing it, I would be curious to see a screenshot of your level where you draw the path that Godot gives you (using _draw())

Astar requires a newer update of godot, 2,2 i believe, which i can't find anywhere sadly. Great idea with the extra collider layer, I thought of doing it in another way, but yours might actually work :D
Manually placing waypoints, is not something I would mind doing, but I fail to see how it will work dynamically, differently than a 2dpath to follow.

Ty for the quick comments :)
I'll attempt to make a quick 2d nav and dump a screenshot here

Here is a fresh level created for this thresh:
http://prntscr.com/dc3bcd (sick Paint.net skills I know)

Here is the code:

Also there is another script, which changes "turn" to 2, and sets "PC_pos" to the blue guys position

The red guy is the start pos (Sprite)
As i play the scene:
It marks out the corners of the obstackle so if i move the guy, it will NOT pass through the middle of the open tile, but rather just barely skip past the obstacles corner.
For some reason it instantly jumps to the points, I'll have it move 1 tile at a time, but again, I don't know how to make it through the center of the tiles, except maybe with your idea of making a new coll layer :)

Here I've tried drawing out the path I would like it to take in lightshot:

What do you get if you center points of the path using tilemap's point = world_to_map(point) followed by point = map_to_world(point) + tile_size/2.0?

I don't understand. How would you get "point"? Would that be the individual parts of the path? path[i]?
I'm guessing that would look like this in the code:
I have no clue. This ends up like this:

You missed half of the formula:

var tilemap = get_parent().get_node("tilemap")
pos = tilemap.map_to_world(tilemap.world_to_map(path[i])) + tilemap.get_cell_size()/2.0
draw_circle(pos, 10, Color(1,1,1))

You are a god Zylann! Thank you so much, this has saved my week!
Now I just need to make it follow that path for 50 pixels a turn and I can get rid of my 80 lines of shit script xD

Thanks a bunch mate :)
Really, taking your time out to teach a random stranger to do something is quite something ^^

I was only 50% sure that this would work, but it does so I'm happy too^^

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.