SOLVED Having an object gravitate towards another object based on distance.

I'm essentially trying to create an object that sort of "magnetizes" to the player object. After a certain radius, the object begins to slowly but surely gravitate towards the player. The closer the object is to the player, the faster its speed is.

What I have right now is:

if (distance_to_object(o_player) < 100) {
    direction = point_direction(x,y,o_player.x,o_player.y);
    speed = 1;
Which I know would begin to move this object towards o_player once o_player is within 100 distance. However, this would move at full speed as soon as the radius is breached. How can I make it so its speed depends on how far away the player is, as described above?


You're already calculating distance_to_object. That is a number that you have. Then you do math with the number.
Last edited: