i am using AI to control my player nodes, along with a navigation node and some obstacle avoidance code, but sometimes the raycast2D nodes get stuck on some collisionshapes for no apparent reasons, code below along with all relevant info.
Thank you in advance for your help!
RAYCAST2D CONTROLLING FUNCTION:
func avoid_obstacles() -> Vector2:
var avoid_vel = Vector2.ZERO
raycasts.rotation = navigate().angle()
for raycast in raycasts.get_children():
if raycast.is_colliding():
var obstacle_dir = (global_position - raycast.get_collision_point()).normalized()
var obstacle_interest = navigate().normalized().dot((raycast.get_collision_point() - global_position).normalized())
if obstacle_interest >= 0.5 && raycast.name == "RayCast2D":
avoid_vel += obstacle_dir.rotated(deg2rad(90))
elif obstacle_interest >= 0.5 && raycast.name == "RayCast2D2":
avoid_vel += -velocity
elif obstacle_interest >= 0.5 && raycast.name == "RayCast2D3":
avoid_vel += obstacle_dir.rotated(deg2rad(-90))
elif obstacle_interest >= 0:
avoid_vel += obstacle_dir
return avoid_vel.normalized() * avoid_force
i believe this is due to the raycast2Ds not colliding correctly but i have no idea how to fix it, here is a video of how that looks : https://streamable.com/1asnho
Full player code in pastebin : https://pastebin.com/W8Gjtsq8
PS : i am not using a tilemap but a navigationpolygoninstance.