Measure distance
#1

I'm here asking how to measure a certain distance, as i saw on gamerx the race stats, showing the track lenght of the race: 6.21km. So, i'd like to know how to measure a certain lenght on KM.
Reply
#2

There are few ways to do this, based on timers. You can, for example, check player's vehicle speed every second and depending on it, you can add some values to the distance variable. Look for mileages filterscripts on forums and edit it for your own needs.
Reply
#3

You'll need a algorithm, its not that easy finding a distance from one point to another and calculating the KM. No, you don't need a timer for this.
Reply
#4

You just have to calculate the distance between all checkpoints and add it with each other. Easy as that.
Reply
#5

pawn Код:
stock GetDistance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
  new Float:rst, Float:xd, Float:yd, Float:zd;
  x1 = floatabs(x1); x2 = floatabs(x2); y1 = floatabs(y1); y2 = floatabs(y2); z1 = floatabs(z1); z2 = floatabs(z2);
  xd = x2 - x1; xd = floatabs(xd);
  yd = y2 - y1; yd = floatabs(yd);
  zd = z2 - z2; zd = floatabs(zd);
  rst = ((xd * xd) + (yd * yd*) + (zd * zd));
  return rst;
}
a code to calculate the distance between each checkpoint... I have no clue whether this actually works however you might want to try it out xD
Reply
#6

thanks 4all
Reply
#7

ohh yea <<< post after this
Reply
#8

Yeah but most races aren't just a straight shot. You need to do what the earlier post said. Add the distances from each checkpoint to the next. You don't even need to do it during run-time unless you're lazy. It might take time but it's not hard.

pawn Код:
dist = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)
There's a 3d distance formula.
Reply
#9

Quote:
Originally Posted by Sascha
Посмотреть сообщение
pawn Код:
stock GetDistance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
  new Float:rst, Float:xd, Float:yd, Float:zd;
  x1 = floatabs(x1); x2 = floatabs(x2); y1 = floatabs(y1); y2 = floatabs(y2); z1 = floatabs(z1); z2 = floatabs(z2);
  xd = x2 - x1; xd = floatabs(xd);
  yd = y2 - y1; yd = floatabs(yd);
  zd = z2 - z2; zd = floatabs(zd);
  rst = ((xd * xd) + (yd * yd*) + (zd * zd));
  return rst;
}
a code to calculate the distance between each checkpoint... I have no clue whether this actually works however you might want to try it out xD
Код:
#define DISTANCE(%1,%2,%3,%4,%5,%6) floatsqroot((%1-%4)*(%1-%4) + (%2-%5)*(%2-%5) + (%3-%6)*(%3-%6))
KAPOW!! one line XD
just use like distance = DISTANCE( x1, y1, z1, x2, y2, z2);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)