Enemy to follow my character, object following object, (video inside)

I have been working on some code the last couple of days trying to wrap my head around this problem I have been having. I have successfully done some research on the forum and put together some code that works for an enemy to follow my character using transitionTo.

In the video below you will see that the grey circle moves towards the red one and stops once it gets to a certain location.

https://youtu.be/bQK3UhKkfYg

As you can see in the video, the issue is when I decide to move the red character, the grey circle does not move at a constant rate. it seems to slow down the closer it gets to the red character. When I move the red character towards and hopefully through the grey circle, the grey circle speeds up so it is never passed. When I move the red circle away from the grey circle the grey circle falls way behind.

I would ultimately like the red character to be slightly faster than the grey circle and I would like to achieve a constant rate of “chase” for the grey circle.

I have been trying to avoid the physics engine because I don’t think it is necessary for the game and I have enabled the red and green characters to move quite well without it.

Here is the code that I have for the grey circle movement

---------------------------------------------------- -- Enemy chase player ---------------------------------------------------- local function enemyDist(x1, y1, x2, y2) local xFactor = x2 - x1 local yFactor = y2 - y1 local dist = math.sqrt((xFactor\*xFactor) + (yFactor\*yFactor)) return dist end local function enemyFollow(event) transition.moveTo (enemy1, {x=target.x + 120, y=target.y, time= enemyDist(enemy1.x, enemy1.y, target.x, target.y)/.15}) depthSort(charGroup) -- this sorts the layers characters are on, works just fine here end

and of course the event listener

Runtime:addEventListener("enterFrame", enemyFollow) -- for enemy movement

Why not just set a transition on the grey ball at the same time as you set it on the red one?

long story short. the problem of the grey ball slowing down was due to the transition x location. With the added +120 it would create that slowing effect, im not sure why, but I removed the +120 and it worked just fine. I made a simple work around that would still make the grey ball stop +120 away from the red

Why not just set a transition on the grey ball at the same time as you set it on the red one?

long story short. the problem of the grey ball slowing down was due to the transition x location. With the added +120 it would create that slowing effect, im not sure why, but I removed the +120 and it worked just fine. I made a simple work around that would still make the grey ball stop +120 away from the red