• 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!

Legacy GM Position on path (while not moving along path)?

S

ScaryPotato

Guest
I'm working on a racing game, and have been trying to figure out a consistent way to display who's in 1st/2nd/3rd etc, and this is what I have right now.

There's a path running down the middle of the track, and on it, I've got an object moving along it (ahead of oNPC and oPlayer), and use point_distance to calculate which racer is closest to it. The idea works well enough for 3 racers, but think I can use an array to store the distance information.

My real question is this: Is there a way for oNPC and oPlayer to track where they are on that path, even though they're not moving along the path? It seems like it would be a much cleaner way of the tracking progress of each lap if it's possible to do.

Thanks in advance for any insight you have!


GML:
var Nearest=instance_nearest(x, y, oNPC);
var Furthest=instance_furthest(x, y, oNPC);
var Middle=instance_nearest(Nearest.x, Nearest.y, oNPC);
var Player=oPlayer;


if (point_distance(x, y, Player.x, Player.y) < point_distance(x, y, Nearest.x, Nearest.y))
{draw_text(Player.x, Player.y-32, "1st");}

if ((point_distance(x, y, Player.x, Player.y) > point_distance(x, y, Nearest.x, Nearest.y)) && (point_distance(x, y, Player.x, Player.y) < point_distance(x, y, Middle.x, Middle.y)))
{draw_text(Player.x, Player.y-32, "2nd");}

if ((point_distance(x, y, Player.x, Player.y) > point_distance(x, y, Middle.x, Middle.y)) && (point_distance(x, y, Player.x, Player.y) < point_distance(x, y, Furthest.x, Furthest.y)))
{draw_text(Player.x, Player.y-32, "3rd");}

if (point_distance(x, y, Player.x, Player.y) > point_distance(x, y, Furthest.x, Furthest.y))
{draw_text(Player.x, Player.y-32, "4th");}
 
Top