What's velocity?
#1

Hello, now I know all of these velocity functions for a long time, but now I'm kinda confused, what does this number actually mean? Is it units per second, units per millisecond, or something completely else. The problem is - it's hard to test it.
Reply
#2

What don't you understand?
https://sampwiki.blast.hk/wiki/SetPlayerVelocity - explains.
Reply
#3

Velocity is the rate of your change in position in vector.
Reply
#4

Ah c'mon, I know there's sa-mp wiki, but for instance, now, let's say I've got an object with velocity 1, how far it will be after, let's say 5ms?
Reply
#5

Easy to calculate. Use the simple formulas you've seen in the past in the physics lessons:
Код:
Δs = (a * (Δt)І) / 2
Код:
Δv = a * Δt
Now just substitute Δv into the first formula:
Код:
Δs = (v * Δt) / 2
Now fill in:
Код:
Given: 
- Δv(elocity) = 1
- Δt(ime) = 5 ms. = 0.005 seconds

Asked:
- Δs(distance traveled)

Solution:
- Δs = (1 * 0.005) / 2 = 0.0025 (meters) but in-game, these are units
Should be pretty much the same in-game.
Reply
#6

Hadn't yet actually encountered these, but well, lot's of physics lessons to visit in future, but the problem here is, that you assume that game units divided by velocity are seconds rather than ms or μs , and well, just so that you know, velocity of 1.4 was avg for me with hydra. Btw, nice delta symbol.
Reply
#7

Thanks for explanation. It was very helpful.

I guess now I can fire off directly what I'm making - a FP camera in car camera.

Why I need velocity? Simple - let's consider that we have absolute position, which we get with GetPlayerPosition, next we've got the view offset - where from and where to we want our view to be, which is pretty much calculating the front and adding more offset.

And finally we've got the time offset. When we get OnPlayerUpdate, any actions that may require to be sent to client will have time about equal to GetPlayerPing, so now we've calculated where we would want our camera to be for standing vehicle, so now it's up to GetPlayerVelocity*ping what's the time offset.

But it doesn't stop here, the reason I started making this was because I figured out that using velocity gives previously unseen ability - predicting, so now, for example, we may have got a camera that's going back and forth about 10 or 20 times per second, because it's updated each OnPlayerUpdate, so in the time when next OnPlayerUpdate is called, our camera is just standing there while our vehicle doesn't stop the movement.

So now, we clearly need to make it smooth(er) and we know, that with maths, we can predict how far it'll have driven each 5 or 2 ms, that means, that in this OnPlayerUpdate - OnPlayerUpdate time we have to make predictions each 2 ms, and send them to the client, so best case - vehicle goes straight, camera remains normal, vehicle turns, camera follows with delay or again returns to bad jumping around habit, then we'll involve more maths.

Ok, so the problem for this whole idea is :
1.Pawn and float together works bad, but skipping pawn isn't so hard
2. How the fuck to use velocity to determine actual distance in miliseconds. I know, velocity*time=length but then we need to know what's the unit of velocity, because otherwise the length is wrong!

Now that you know my secret plan that I could've sold, you can help coding it as free include.
Reply
#8

first of all then you need the more advanced maths of the Velocity family
then you need to consider in what type your formulat give the answers: degrees or radians? (however conversion is fairly simple)

And I would like to say that GetVehicleVelocity has nothing to do with time but I know that this is not true however very hard to prove here as it comes to Headings, Directions and Speeds in just 3 variables (X, Y ,Z) which can be negative too. And speed is ALWAYS related to distance and time.
I actually prepared a test:
pawn Код:
#include <a_samp>

new
    Float:X[4][MAX_PLAYERS],
    Float:Y[4][MAX_PLAYERS],
    Float:Z[4][MAX_PLAYERS],
   
    time_start[MAX_PLAYERS] = {0,...},
    time_end[MAX_PLAYERS] = {0,...},
   
    Float:distance[4][MAX_PLAYERS];

#define p(%1) %1[playerid]//ye I know I am lazy...

public OnPlayerUpdate(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
   
    GetVehiclePos(vehicleid,p(X[0]),p(Y[0]),p(Z[0]));
   
    p(distance[0]) = GetDistance(p(X[0]),p(Y[0]),p(Z[0]),p(X[1]),p(Y[1]),p(Z[1]));
    time_start[playerid] = GetTickCount();
    GetVehicleVelocity(vehicleid,p(X[2]),p(Y[2]),p(Z[2]));
   
    p(distance[2]) =
    floatsqroot
    (
        floatpower(p(X[2]),2)
        +
        floatpower(p(Y[2]),2)
        +
        floatpower(p(Z[2]),2)
    )
    ;
   
    printf("Distance traveled: %f, velocity that should be equal: %f, Time passed since last update: %dms",distance[0],distance[2],time_start[playerid]-time_end[playerid]);
    printf("Old Distance traveled: %f, Old velocity that should be equal: %f",distance[1],distance[3]);
   
    p(X[1]) = p(X[0]),
    p(Y[1]) = p(Y[0]),
    p(Z[1]) = p(Z[0]),
    p(X[3]) = p(X[2]),
    p(Y[3]) = p(Y[2]),
    p(Z[3]) = p(Z[2]),
   
    p(distance[1]) = p(distance[0]),
    p(distance[3]) = p(distance[2]);
    time_end[playerid] = time_start[playerid];
    return 1;
}

#undef p

forward Float:GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 );
stock Float:GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatsqroot
    (
        (
            (
                x1 - x2
            )
            *
            (
                x1 - x2
            )
        )
        +
        (
            (
                y1 - y2
            )
            *
            (
                y1 - y2
            )
        )
        +
        (
            (
                z1 - z2
            )
            *
            (
                z1 - z2
            )
        )
    )
    ;
}
I have written it RAW even without compilation, it's 1:10 AM, there CAN be errors or this can be totally incorrect!



I have found this:
Definition 2: Velocity
Velocity is the rate of change of position vector with respect to time and is expressed as the ratio of change in position vector and time.
Reply
#9

Thanks, just what I needed. Should I report my final results somewhere?
Reply
#10

would be nice if you did it here :P
Reply
#11

sorry for asking this here but i need it
Gamer_Z where u find that map mod can u give me link please i realy like it xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)