10.03.2009, 19:47
I would understand this if it was on my own language but on english it is a little bit harder.
A few days ago I was working on my drift script and for the first time I came across calculating speed in coordinator system (in script, I have done it before on paper). Now I have just some questions about the functions. I know how to calculate the distance between two points (on paper) but I just dont understand some of the functions in this equation. Here is what I did find:
This is for the distance between two points and I do understand the equation itself but I dont understand what this floatpower and floatsub means. I know floatabs is that the distance will always be positive and that floatsqroot is well root and I gues that this number 2 is square. If I was writing this code it would be something like this:
floatabs(distance) = floatsqroot((OldX[playerid] - X) (here now comes square function that I dont know)) and same step for Y and Z coordinators.
And now comes some value that I dont understand why it is multiplyed with distance:
Dont get me wrong the script is working great but I just want to understand it.
Here is the whole code
So basicly this is what I want to know.
What is floatpower for?
What is floatsub for?
What is floatround for?
And why is this distance multiplyed with 5000? I would not do that if I was writing the code, I would just return the speed that equalls distance from the equation divided with time from the timer.
Any help or tips are very welcome.
EDIT: And please dont give me the links from wiki because I used search but I dont understand it quite well because it is on english.
A few days ago I was working on my drift script and for the first time I came across calculating speed in coordinator system (in script, I have done it before on paper). Now I have just some questions about the functions. I know how to calculate the distance between two points (on paper) but I just dont understand some of the functions in this equation. Here is what I did find:
pawn Код:
floatsqroot(floatpower(floatabs(floatsub(X,OldX[playerid])),2)+floatpower(floatabs(floatsub(Y,OldY[playerid])),2)+floatpower(floatabs(floatsub(Z,OldZ[playerid])),2));
floatabs(distance) = floatsqroot((OldX[playerid] - X) (here now comes square function that I dont know)) and same step for Y and Z coordinators.
And now comes some value that I dont understand why it is multiplyed with distance:
pawn Код:
value = floatround(distance * 5000);
Here is the whole code
pawn Код:
stock GetPlayerSpeed(playerid)
{
new value;
new Float:distance, Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
distance = floatsqroot(floatpower(floatabs(floatsub(X,OldX[playerid])),2)+floatpower(floatabs(floatsub(Y,OldY[playerid])),2)+floatpower(floatabs(floatsub(Z,OldZ[playerid])),2));
value = floatround(distance * 5000);
return floatround(value/time); // time from the timer
}
What is floatpower for?
What is floatsub for?
What is floatround for?
And why is this distance multiplyed with 5000? I would not do that if I was writing the code, I would just return the speed that equalls distance from the equation divided with time from the timer.
Any help or tips are very welcome.
EDIT: And please dont give me the links from wiki because I used search but I dont understand it quite well because it is on english.

