One mathematic discussion
#1

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:

pawn Код:
floatsqroot(floatpower(floatabs(floatsub(X,OldX[playerid])),2)+floatpower(floatabs(floatsub(Y,OldY[playerid])),2)+floatpower(floatabs(floatsub(Z,OldZ[playerid])),2));
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:

pawn Код:
value = floatround(distance * 5000);
Dont get me wrong the script is working great but I just want to understand it.

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
}
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.
Reply
#2

Why is this off topic? I need help with scripting. God damn
Reply
#3

Ever heard of the wiki?
Reply
#4

Quote:
Originally Posted by Finn
OMG. Ever heard of stop spaming and read the post till end.
Reply
#5

Ever heard of learning some english? Try learn some english before you script. It will help alot.

Leopard.
Reply
#6

Ok I have learn english can you now tell me why is the distance multiplyed with 5000?
Reply
#7

Let's say player coord X was 80. The he moves and gets to 82. then it gives some calculation (don't bother now to count), then it multiply with 5000 to get a realistic speed. Such as in KPH.

Leopard
Reply
#8

Quote:
Originally Posted by [K4L
Leopard ]
Let's say player coord X was 80. The he moves and gets to 82. then it gives some calculation (don't bother now to count), then it multiply with 5000 to get a realistic speed. Such as in KPH.

Leopard
Thank you very much now I know and understand the whole equation

EDIT: When I want to get km/h it is multiplyed with 5000 or some other number?
Reply
#9

Quote:
Originally Posted by Dujma
Quote:
Originally Posted by [K4L
Leopard ]
Let's say player coord X was 80. The he moves and gets to 82. then it gives some calculation (don't bother now to count), then it multiply with 5000 to get a realistic speed. Such as in KPH.

Leopard
Thank you very much now I know and understand the whole equation

EDIT: When I want to get km/h it is multiplyed with 5000 or some other number?
I think you've to try some factors unless you get something which is nearly realistic.
And as the coordinates in the game aren't really fixed you can variegate the factor as much as you think it is realistic.
Reply
#10

Well since your discussing only scripting, this is in the wrong section.
Reply
#11

What you multiply by depends on the length of the timer you would be updating this in.

If it was 1 second, then the output would be GameUnits /ps. So near enough to m/s.

Through the magic of ******, I found that to get kph out of a m/s input you times the input by 3.6

But, if the timer is NOT 1 second, then it becomes more difficult, and less accurate.
Reply
#12

Quote:
Originally Posted by kc
What you multiply by depends on the length of the timer you would be updating this in.

If it was 1 second, then the output would be GameUnits /ps. So near enough to m/s.

Through the magic of ******, I found that to get kph out of a m/s input you times the input by 3.6

But, if the timer is NOT 1 second, then it becomes more difficult, and less accurate.
But if you change the timer you should only change the time variable that is deviding with distance? Not touch this "realistic" number. That is how I understand it...

You get distance in coordinate system and you need to transform it to realistic distance and you just multiply it with some number and that has nothing to do with time. Or it does?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)