# 2D Enemy Follow Player with collision detection

Attention Topic was automatically imported from the old Question2Answer platform.

Hi,

i currently work on EnemyAI and try to let follow an enemy the Player.
So on, this will work, but i don’t get a collision detection.

As you can see here, there are many collisions and i want the enemy walk arround this.
But i don’t get it.

Only the Green Grass is sayed it is an Navigation. My Tree Construct is this:

My Code for this Event is this (the Enemy does not follow the Path, maybe you see the fail)

``````	if Navi != null:
var path = Navi.get_simple_path(player.global_position, global_position)
Line.points = path
if path.size() > 1:
var start_point = position
var distance = MovementSpeed * delta
for i  in range(path.size()):
var distance_to_next = start_point.distance_to(path[0])
if distance <= distance_to_next and distance >= 0 :
position = start_point.linear_interpolate(path[0], (distance * 5)/distance_to_next)
break
elif distance < 0:
position = path[0]
distance -= distance_to_next
start_point = path[0]
path.remove(0)
``````

i hope you can help and understand me!

Greetings,
Daniel

Hey! Her`s something I found in the Internet:
https://www.davidepesce.com/navigation2d-tutorial/navigation2d-tutorial.html (are you looking for something like this? Her´s the totorial: https://www.davidepesce.com/2019/11/19/godot-tutorial-how-to-use-navigation2d-for-pathfinding/

ah ok, so i have to do this manually?
Thank you.

Maybe you can me help with this:
I have decided to change my movement to an gridbased movement. I don’t get it to change my navigation to this movement and don’t found any tutorial for that.

Do you have a idea how to change this?
My Current Movement without Navigation

``````var Real_Walk_direction = Walk_direction * Constant.TILE_SIZE
if Real_Walk_direction != Vector2.ZERO:
CollisionDetiectionSnap.cast_to = Real_Walk_direction
CollisionDetiectionSnap.force_raycast_update()
if !CollisionDetiectionSnap.is_colliding():
SmoothAnimation.interpolate_property(self, "position", position, position + Real_Walk_direction, 1.0 / Speed,  Tween.TRANS_SINE, Tween.EASE_IN_OUT)
SmoothAnimation.start()
``````

rotzend | 2020-12-18 11:18

It`s my solution. (I`d never say it`s the only one. But I have no idea how to change your code. Sorry

Bimi124 | 2020-12-19 08:51