Jump to content
Sign in to follow this  
PYL

Calculated speed and acceleration are not accurate

Recommended Posts

Hello, to calculate an object acceleration I made this little function:

[] spawn
{
    while {alive player} do
    {
        dt = 0.001;
        xA = getPosVisual player;
        sleep dt;
        xB = getPosVisual player;
        dx = xB vectorDiff xA;
        d = dx vectorMultiply (1/dt);
        hintSilent format ["Derivative speed km/h = %1 \nOfficial speed km/h = %2", 3.6*(vectorMagnitude d), 3.6*(vectorMagnitude(velocity player))];
    };
};

Actually this works for the speed but it's the same to get the acceleration: I chose speed because we know what sould be the real speed (velocity X).

Does somebody know what could be the problem? I think it's in the sleep command since the game looks like it's waiting a different time than the one you divide to get the derivative...

Please test this script in the VR editor to check yourself, maybe creating a car or plane. Cheers!

Share this post


Link to post
Share on other sites

The issue is likely the assumption than the sleep step is accurate, which requires at least 1/dt (= 1000) FPS.

You are better off using diag_tickTime to measure actual elapsed time since last iteration.

 

Also, be careful with the default position format, as it uses the terrain surface as a datum. Moving truly horizontally over uneven ground gives a change in position Z. Use visiblePositionASL instead.

 

One more, if you use "vehicle player" rather than "player" the script will continue to work if the player is in a vehicle.

 

Also, Arma's script language uses floating point numbers, so the precision when comparing two very similar numbers or vectors is low. Prior to the vectorMagnitude command being added, I have also tried to measure speed from first principles and came to the conclusion that over small time intervals, velocity can be trusted more than derived speed from position measurements.

Share this post


Link to post
Share on other sites

Hi and thanks for the detailed explanation. Do you know the difference between diag_frameNo and diag_tickTime? To me it looks like diag_frameNo is 1000*diag_tickTime? I would like this feature to wait 1 frame to get the derivative and I was unsure what was the difference since I tested both and they looked like the same.. 

Share this post


Link to post
Share on other sites

Refer to the BI wiki for command references.

Unless your FPS is always constant (impossible) there is no relationship between the two commands, other than they both go up the longer the game has been running.

To execute script on every frame, the easiest thing to do is to use the onEachFrame command. You'll need to remove all sleep commands, instead have the script remember last frame's info, then compare with current frames.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×