Enemy AI not working

Hallo!
I’ve got a script witch should let the enemies go to player then he is in range. the problem is, the enemies are not moving.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAI : MonoBehaviour {
    public Transform player;

    Vector2 destination;
    Vector2 place;
    Vector2 journey;

    // Max and mit Dastance to Move
    float minDistanceToPlayer = 0.5f;
    float maxDistanceToPlayer = 4f;

    public int speed = 50;

    Rigidbody2D rb;
    void Start () {
        rb = GetComponent<Rigidbody2D> ();
    }
    

    void Update () {
        


        moveToPlayer ();
        lookAtPlayer ();    
    
    
            }


    void moveToPlayer() {
        destination = player.transform.position;
        place = transform.position;

        journey.x = destination.x - place.x;
        journey.y = destination.y - place.y;

        if(Vector2.Distance(place, destination)<4 ) {
        rb.velocity = new Vector2 (journey.normalized.x * speed * Time.deltaTime, journey.normalized.y *  speed * Time.deltaTime);

        Vector2 v = rb.velocity;
        float angle = Mathf.Atan2 (v.y, v.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
    }

    }

    void lookAtPlayer() {
    //    float rotation_z = Mathf.Atan2 (diff.y, diff.x) * Mathf.Rad2Deg;
    //    transform.rotation = Quaternion.Euler (0, 0, rotation_z    );


    }

}

Thank you for help!

If the distance from the player to the enemies is greater than 4 they won’t attempt to move (line 43).

Put a breakpoint on line 44 and attach the debugger and run, make sure you are reaching that code. Or else do a:

Debug.Log("distance=" + Vector2.Distance(place,destination).ToString());

right before the if statement to see how far away they are.

Not sure but I think if the player gets away from the enemies, they will continue moving in their last commanded direction,which is probably not what you want, so you probably want to stop them when they cannot chase the player anymore by setting their velocity to zero.

Okay thank you. I do not know what was the problem, but I now using Vector3.Distance instead of Vector2.Distance. Now its working.