# Time and Sleep not accurate

## Recommended Posts

So i was throwing around a hunter at 100 m/s and i noticed that Sleep and Time are not on the same scale. I was getting values between 95m/s and 105m/s based on my script calculations.

[color="#FF8040"][color="#006400"][i]//car1 is Hunter in first testing phase(Reliable no drag vehicle)[/i][/color]
car1 [color="#191970"][b]setVelocity[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]100[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]100[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]hint[/b][/color] [color="#7A7A7A"]"start"[/color][color="#8B3E2F"][b];[/b][/color]
Vms[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]velocity[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
Posi1[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPos[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
Sec1[color="#8B3E2F"][b]=[/b][/color] [color="#000000"]time[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
Posi2[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPos[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
sec2[color="#8B3E2F"][b]=[/b][/color] [color="#000000"]time[/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]//Gets time and position of "car1" at 2 different points[/i][/color]

Dsec[color="#8B3E2F"][b]=[/b][/color] sec2[color="#8B3E2F"][b]-[/b][/color]sec1[color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]//Get relative of sec1 and sec2[/i][/color]
Dposi[color="#8B3E2F"][b]=[/b][/color] Posi2[color="#8B3E2F"][b]-[/b][/color]Posi1[color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]//Get relative of Posi1 and Posi2[/i][/color]

Timems[color="#8B3E2F"][b]=[/b][/color] Dposi[color="#8B3E2F"][b]/[/b][/color]Dsec[color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//measure m/s of object according to game "time" command[/i][/color]
Sleepms[color="#8B3E2F"][b]=[/b][/color] Dposi[color="#8B3E2F"][b]/[/b][/color][color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//measure m/s of object according to game "sleep" command[/i][/color]

[color="#191970"][b]hint[/b][/color] [color="#191970"][b]format[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"%1m/s according to Sleep, %2m/s according to Time, %3m/s according to Velocity"[/color][color="#8B3E2F"][b],[/b][/color]Sleepms[color="#8B3E2F"][b],[/b][/color]Timems[color="#8B3E2F"][b],[/b][/color]Vms[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Im thinking of maybe throwing 2 hunters at the same time, 1 at 50m/s and the other at 100m/s. Based on that i should be able to extract accurate time relative to velocity which stays constant. Will post results.

Basically from all this I'm just trying measure projectile velocities at certain distance and time intervals. I can then play with that data to better understand arma 3 ballistics.

EDIT:

Added code to get accurate time relative to velocity. Pretty obvious but could prove useful in sme of its elements.

[color="#FF8040"][color="#006400"][i]//car1[/i][/color]
car1 [color="#191970"][b]setVelocity[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]100[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]100[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]hint[/b][/color] [color="#7A7A7A"]"start"[/color][color="#8B3E2F"][b];[/b][/color]
Vms[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]velocity[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
Posi1[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPos[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
Posi2[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPos[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]

Dposi[color="#8B3E2F"][b]=[/b][/color] Posi2[color="#8B3E2F"][b]-[/b][/color]Posi1[color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//relative distance[/i][/color]
Vtime[color="#8B3E2F"][b]=[/b][/color] Dposi[color="#8B3E2F"][b]/[/b][/color]Vms[color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//Distance divided by velocity gets time[/i][/color]

[color="#191970"][b]hint[/b][/color] [color="#191970"][b]format[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"%1 Seconds, %2 Meters"[/color][color="#8B3E2F"][b],[/b][/color]Vtime[color="#8B3E2F"][b],[/b][/color]Dposi[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

I could probably have something like this running in the background for an accurate time scale for measuring other objects velocities.

Simulation run on VR map

Edited by Benargee

##### Share on other sites

some of what you are experiencing is more then likely related to how you are executing those tests. (scheduled vs un-scheduled) environments. if your just executing them using "execVM" then they are getting put in a scheduler and checked to see if it's ok to run them. (the game engines way of trying to prevent a traffic jam basically)

if your just looking into this stuff just for ballistics then looking at the config for the ammo is a better way to go - https://community.bistudio.com/wiki/CfgAmmo_Config_Reference

Edited by Nimrod_Z

##### Share on other sites

Edit: never mind, missed part of your post

##### Share on other sites

I'm not in front of a Arma computer to test my guess, but i think this could be caused by the getPos command, as it needs time to execute.

Try just:

sleep 1;
Sec1= time;
sleep 1;
sec2= time;

And check again.

Now if this returns correct values, tryother getPos commands like:

getPosWorld (dev branch only)

getPosATL and getPosASL (both should be faster than getPos)

visiblePosition

position

just to name some.

##### Share on other sites
some of what you are experiencing is more then likely related to how you are executing those tests. (scheduled vs un-scheduled) environments. if your just executing them using "execVM" then they are getting put in a scheduler and checked to see if it's ok to run them. (the game engines way of trying to prevent a traffic jam basically)

if your just looking into this stuff just for ballistics then looking at the config for the ammo is a better way to go - https://community.bistudio.com/wiki/CfgAmmo_Config_Reference

Ok, but how does this explain why I get values above and below what is expected. That means that it is not only slow but also fast. I'll still give your suggestions a try, but take what I said into consideration.

As for configs, I am already aware of them. I know a projectiles muzzle velocity and drag factor, I just want to plot the data so that I can better understand where and when a projectile is space

Edit:

@Lappihuan I will try getPosASL, it actually makes more sense to use that too, since over terrain my projectile Alt would be all over the place. Im also pretty sure I tried your script earlier. The problem was i didnt know who was wrong, time or sleep. I then threw a hunter around and compared time with expected time at its current position.

Edited by Benargee

##### Share on other sites

Ok, so I think I understand whats going on here. Its definatley tied to FPS and Scheduled environments. I basically turned down all my video settings down to potato, i was able to get 700-750 fps that way on VR with just me and a Hunter. I think that if your time between frames is less than 3ms(334FPS), then your scheduled code does not get put on hold.

I wish there was a way to overide the default 3ms for special cases.

Here is my code so far, its half built for debug console use:

[color="#FF8040"][color="#006400"][i]//Works best when game running at 420fps+[/i][/color]
Car1 [color="#191970"][b]setPos[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]4027.95[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]4352.15[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]1.0165944[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//Position near player on meter off ground[/i][/color]
Car1 [color="#191970"][b]setDir[/b][/color] [color="#FF0000"]90[/color][color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//reset direction to 90deg[/i][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]0.1[/color][color="#8B3E2F"][b];[/b][/color]
car1 [color="#191970"][b]setVelocity[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]100[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]100[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]hint[/b][/color] [color="#7A7A7A"]"start"[/color][color="#8B3E2F"][b];[/b][/color]
Vms[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]velocity[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
Posi1[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPosASL[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
TTime1[color="#8B3E2F"][b]=[/b][/color] [color="#000000"]time[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]sleep[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
Posi2[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPosASL[/b][/color] car1 [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
TTime2[color="#8B3E2F"][b]=[/b][/color] [color="#000000"]time[/color][color="#8B3E2F"][b];[/b][/color]

Dposi[color="#8B3E2F"][b]=[/b][/color] Posi2[color="#8B3E2F"][b]-[/b][/color]Posi1[color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//relative distance[/i][/color]
Vtime[color="#8B3E2F"][b]=[/b][/color] Dposi[color="#8B3E2F"][b]/[/b][/color]Vms[color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//Distance divided by velocity gets time[/i][/color]
TTime[color="#8B3E2F"][b]=[/b][/color] TTime2 [color="#8B3E2F"][b]-[/b][/color] TTime1[color="#8B3E2F"][b];[/b][/color]
FPSS[color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]diag_fps[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]hint[/b][/color] [color="#191970"][b]format[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"%1 VSeconds, %3 TSeconds%2 Meters"[/color][color="#8B3E2F"][b],[/b][/color]Vtime[color="#8B3E2F"][b],[/b][/color]Dposi[color="#8B3E2F"][b],[/b][/color]TTime[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][color="#006400"][i]//@700FPS+ i consistently get TTime=1 , no decimals[/i][/color]
Car1 [color="#191970"][b]setPos[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]4027.95[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]4352.15[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]-0.0165944[/color][color="#8B3E2F"][b]][/b][/color][/color]

Edited by Benargee
http://killzonekid.com/sqf-to-bbcode-converter/