Calculate Speed of Vehicle
#1

Hi!

I can't find a working calculus to get my speed-meter working.

I've tried a code that came with a speed-o-meter & one of my own too, but i can't make it work.

Here's the code with what was my old function mixed with someone else's:

Код:
public Float:GetVelocity(playerid,Float:X, Float:Y,Float:Z)
{
	if(IsPlayerConnected(playerid) && IsPlayerInAnyVehicle(playerid))
	{
		    new Float:Distance;
	      GetPlayerPos(playerid, X, Y, Z);
	      Distance = floatsqroot(floatadd(floatadd(floatpower(floatsub(X, OldX[playerid]), 2), floatpower(floatsub(Y, OldY[playerid]), 2)), floatpower(floatsub(Z, OldZ[playerid]), 0)));

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	      OldX[playerid] = X; OldY[playerid] = Y; OldZ[playerid] = Z;
				new Float:Kilometers = floatround(floatmul(Distance, 2.0), floatround_floor);
				
				return Kilometers;
	}
	else return 0.0;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

}
And here the part where I draw it on the screen:

Код:
	new Float:result = GetVelocity(playerid, x,y,z);
	
  new string[128];
  format(string, sizeof(string),"%f", result);
  SendClientMessage(playerid, 0xff0000ff, string);
  
  return 1;
}
I just wanna know why it raises when i accelerate but sometimes i'm going through a straight line and it displays, 70,80, 90, 40, 80, 90, 40 (it goes well below and comes up again to a reasonable number).
Reply


Messages In This Thread
Calculate Speed of Vehicle - by clavador - 02.10.2009, 02:04
Re: Calculate Speed of Vehicle - by Joe Staff - 02.10.2009, 05:44
Re: Calculate Speed of Vehicle - by yezizhu - 02.10.2009, 08:48
Re: Calculate Speed of Vehicle - by Joe Staff - 02.10.2009, 16:38

Forum Jump:


Users browsing this thread: 1 Guest(s)