Topic: Markers stop moving to player??

Good morning, I'm intending to move a marker towards a target and when it is on the way, it stops completely.

My team and I are developing a game with mechanics similar to pokemon go. I want to move a marker (enemy) to my position but when setting small speeds (to make it as real as possible) it stops.

the zoom of my map is 17;

Here are some lines of code:

    void moveEnemy()
    {
       var speed = 0.003f //a little slower than player walking on the street. 

        Vector2 firstPos = myMarker.position;
        float distance= OnlineMapsUtils.DistanceBetweenPoints(myMarkerFirstPos, player.myMarker.position).magnitude;

        while (distance>= 0.05f) //50mts close 
        {
            miMarcador.position = Vector2.Lerp(myMarker.position, player.myMarker.position, speed);
            OnlineMaps.instance.Redraw();
            
        }

    }

ty for help guys

Re: Markers stop moving to player??

Hello.

Your code will not work:
1. It contains an infinite loop (you do not update the distance), and you just freeze your application.
2. Redraw does not redraw the map right now. It simply marks that the map needs to be redrawn. Drawing will starts later.
3. You use Lerp incorrectly, and your enemy will move fast at a big distance (at the beginning) and slowly at a small distance (at the end).

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.