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)

1
2
3
4
5
6
7
8
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

Got a way :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
views:1250 update:2011/10/4 17:12:07
corona forums © 2003-2011