Speed in KMPH
#1

Hello guys.

Код:
GetVehicleVelocity(GetPlayerVehicleID(x),X,Y,Z);
		new Float:temp=floatsqroot((((X ^ 2) + (Y ^ 2) + (Z ^ 2)) * 100) * 1.6);
		new kmph[80];
		format(kmph,sizeof(kmph),"Speed : %i KMP/H",temp);
        TextDrawSetString(speed[x], kmph);
I am not getting the speed in KMPH. It shows a very big number even when the vehicle is not moving.
Reply
#2

The circumflex character (^) isn't the power operator in Pawn, it is the bitwise XOR operator. The right formula is:

pawn Код:
floatsqroot(((x * x) + (y * y) + (z * z)) * 195.12)
Reply
#3

tht gives 0 KMPH when the vehicle is not moving and when it starts moving it gives a very big number. Is floatsqroot required infront of it??
Reply
#4

Yes. Sorry, forgot.
Reply
#5



I get this speed.
Reply
#6

Usually happens when you try to print a float as an integer.
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
Usually happens when you try to print a float as an integer.
I had the same 'issue' when I was creating my own. Use floatround to round up/down and then display it as an integer.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Usually happens when you try to print a float as an integer.
Do you mean, that it should be printed as a float, because he's using it as an integer.
pawn Код:
format(kmph,sizeof(kmph),"Speed : %i KMP/H",temp);
Reply
#9

Quote:
Originally Posted by Dwane
Посмотреть сообщение
Do you mean, that it should be printed as a float, because he's using it as an integer.
pawn Код:
format(kmph,sizeof(kmph),"Speed : %i KMP/H",temp);
He means that either you have to:

A) Display it as a float (horrible idea for speed-o-meters)
B) Use floatround, and get it into integer form and THEN display it
Reply
#10

It can be done as a float without the rest after the dot '.'
pawn Код:
%.0f
If it's 12.45676, it'll display 12!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)