• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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:

Code:
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?
 

Nidoking

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