-
Notifications
You must be signed in to change notification settings - Fork 86
Pathfinding: Implement navigation along paths for characters #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ons to task headers Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…ble cell functions Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…tep listening Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…I pathfinding Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
|
@copilot Fixes:
forgot to complete this point:
Also: Only do the FLoS checking for pathfinding when there is no portal on the way already. Since there might be actually a line of sight but a portal shortens the distance.
|
…ic, is_like_plantable_bomb Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Addressed all feedback in commit 1ad24b4:
|
|
@copilot - anyways, scrap fat_line_of_sight completely. always use pathfinding to a destination. make this a member of the physics world cache just in case for the future.
find_closest_unoccupied_cell should actually be named find_closest_walkable_cell since we're filtering for portals too
|
… find_path_across_islands_many Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Addressed in commits 70bc519 and 187c199:
Note: pathfinding_graph_view refactor to consolidate repeated get_parent/set_visited/for_each_neighbor logic is a larger refactor that I can do in a follow-up if needed. |
|
@copilot Yes, do the followup refactor.
|
…al comparison Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Addressed in commits 9f1b003 and e85b87b:
|
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…r, return un-normalized, add rerouting-to-main easing Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…inding with smaller alpha Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
|
@copilot You completely broke the get_pathfinding_crosshair function. revert to the prev definition } the ONLY changes:
|
… output param, keep rerouting easing Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Reverted to |
|
…AABB drawing Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Added |
|
@copilot In get_pathfinding_movement_direction, if we detect that we've been on the same cell for the past 2 seconds, I'd like the offset to be rotated 90 degrees so that the character is facing with his side to the destination. Increase the angle by 90 degrees every 2 seconds. Reset this offset as soon as we leave the cell. |
… stuck on same cell Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Added stuck detection in commit 8d58210:
|
game/modes/togame/modes/ai/.hppheaders inai/tasks/navmesh_cell_idstruct combining island_id + cell for single comparisoncheck_path_deviation:DEVIATION_CHECK_RANGE_Vadvance_path_if_cell_reached: whennode_index == 0, checks if in half facing towards next cellget_pathfinding_movement_direction:target_crosshair_offsetreference parameterstuck_cellandstuck_timeinai_pathfinding_stateSTUCK_ROTATION_INTERVAL_SECS), rotates crosshair offset by 90 degreesDEBUG_LOGIC_STEP_RECTSfor drawing filled quads (4 vec2 corners)debug_draw_pathfindingnow draws cell AABBs with smaller alpha (40/255)debug_rectsas 2 triangles per rectdebug_rectconstructor taking (pos, size, rotation) usingaugs::make_rect_pointsfind_random_unoccupied_position_within_stepsfind_path_across_islands_many(navigate only to next portal)sound_cue_messagewhen footstep firesDEBUG_PATHFINDING_STARTduring playtestingDEBUG_PATHFINDING_ENDor bombOriginal prompt
Improving bots AI with actual pathfinding
These handle the AI logic that is called every step. The bots are currently very simple, they just walk in random directions, shoot player on sight, and go to his last seen position.
I will need more complex bots.
Initial refactor
First move these ai sources to game/modes/ai/
Now update_arena_mode_ai/post_solve_arena_mode_ai has only high level flow, i want you to move all static functions like
static vec2 handle_random_movementto their own .hpp headers and include then in arena_mode_ai.cpp e.g. ai/tasks/handle_random_movement.hpp, so that we don't get lost in code. So all modular "AI tasks" have their own headerYou're also free to rearrange/refactor any existing AI-related code during this operation.
I'm thinking these arguments
const arena_mode::input& in,
arena_mode_player& player,
are used only for one or two fields, and it's an overkill to have to pass them. Just pass what is necessary from them like is_ffa, money amount and cosmos.
New function: fat_line_of_sight
A fat line of sight (FLoS) exists when querying the physics world cache with:
for_each_intersection_with_polygon with a rectangle facing the target has no entities. So imagine a long rotated rectangle whose one short end (its center exactly) touches/covers the source character (can just touch its center pos), and the other short end touches the destination. How wide ('fat') is that rectangle is defined by a parameter and it can be 100 px for now. This is to ensure nothing will actually stand in characer's way.
This will be used instead of normal ray cast whenever testing navigability/LoS for a character in AI - except for when we want a shooting LoS as that does not need to be "fat".
FLoS should use predefined_queries::pathfinding()
Better random walk
Have a reusable "random walkable cell within n steps" function in pathfinding code. This will be used for "random walking" with a sensible distance.
Most complex task: start_pathfinding
A bot needs to be able to navigate to any point on the map (given its unoccupied). And use it for when chasing the player.
Navigating the path
Bot must gradually navigate the pathfinding_path returned from find_path_across_islands_many.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.