how can I make moving objects to event go slower the further they are away?

This code is used to move the player’s .x to the events.
Unfortunately it moves FASTER the furthur away it is. (because the speed comes from the distance to the event)

[lua]function move()
if touch == true then
print(“x=”…eventx…", y="…eventy)
distancex = eventx - player.x
distancey = eventy - player.y
player.x = player.x + 500/distancex
end
end[/lua]

I am never good a things like this :confused: how can I get it to go slower when far away and faster closer up? [import]uid: 79135 topic_id: 14493 reply_id: 314493[/import]

Got a way :slight_smile:

[lua]function move()
if touch == true then
print(“x=”…eventx…", y="…eventy)
distancex = eventx - player.x
distancey = eventy - player.y
if distancex < 100 then
player.x = player.x + distancex/10
else
player.x = player.x + display.contentWidth/distancex
end
if distancey < 100 then
player.y = player.y + distancey/10
else
player.y = player.y + display.contentHeight/distancey
end

end
end[/lua]

unfortunately the .x and .y speeds are differant… should of seen that coming, need diagonal distance/speed. [import]uid: 79135 topic_id: 14493 reply_id: 53640[/import]