KinematicBody2D Getting Stuck
Hello, I am having some issues with a KinematicBody2D, it is supposed to represent an enemy that chases the player around, however, when it runs into a wall or other objects, it gets stuck and takes a long time to free itself and resume chase.
I have tried changing the collision shape from a capsule to a circle, changing the radius, lowering the friction value (even setting it to 0) and the issue persists. I am using move_and_slide() to handle movement and I thought that would prevent it from getting stuck like that, but it hasn't worked out well.
Here's a screenshot of what I'm talking about:
I'm thinking of using raycasts to either avoid the walls or give the enemy a shove in the opposite direction whenever it gets stuck, but I don't know how to handle it smoothly so movement is preserved and it doesn't look like it suddenly bounces or changes direction.
Here's the code that handles movement:
var velocity = Vector2() var direction = Vector2() func process_movement(): direction = direction.normalized() velocity = direction if(is_sprinting): velocity = velocity * sprint_speed else: velocity = velocity * walk_speed velocity = move_and_slide(velocity)
Direction is obtained via a Navigation2D node and the get_simple_path() function.