Hey!
I implemented a basic chasing state for my enemy in my 2D Top-Down game. The issue I'm having is since the origin of all my characters are on the feet (for more consistent Y sorting), sometimes my enemy get stuck on corners since it's collision is above his origin point.
Here is a video showing what's happening:
And here is my code:
func fixed_update(delta : float):
controller.move_dir = get_direction_to_chase_target(col if col != null else actor_to_chase)
controller.update_velocity(controller.speed_walk,delta)
controller.move_and_slide()
func get_direction_to_chase_target(target_actor) -> Vector2:
if target_actor == null:
return Vector2.ZERO
if nav_agent == null:
return Vector2.ZERO
nav_agent.target_position = target_actor.global_position
var current_position = controller.global_position
#Get Next position from Nav Agent Calculations
var next_position = nav_agent.get_next_path_position()
return current_position.direction_to(next_position)
So, how I can I make a proper avoidance system when this happens? I'm thinking about raycasting when this happens but not sure how to implement the actual avoidance.
Increasing the navmesh radius won't work since it would need a really big radius to avoid this problem completely and it'll probably cause issues on tight corridors
Thanks!