sakura_chan 9 Posted August 31, 2013 I am working on a velocity based script that slows an object from an unknown speed down to a specific speed. It was working fine when I used a basic "while {(_velocity select 2) <= -3}" line with a loop that removed some velocity and was timed with a "sleep 0.01" command. It was working until I tried it on my laptop which gets about 10-20 fps instead of my desktop's solid 60fps. The object still slowed down but at a much slower rate. Doesn't this mean that "sleep" is unreliable? Are there any alternatives to using it that would not be fps dependant? One workaround I found was to use: while {(_velocity select 2) <= -3} do { _fps = (diag_fps / 60); _chutevel = velocity _chute; _velocity = [_chutevel select 0,_chutevel select 1,(_velocity select 2) + (0.3 / _fps)]; _chute setvelocity _velocity; hintsilent format ["slowing %1\n%2 FPS", _velocity select 2, round diag_fps]; sleep 0.01; }; So the actually amount of deceleration is based on the framerate. Share this post Link to post Share on other sites
ceeeb 147 Posted September 1, 2013 The game simulation only runs one update per frame, so the minimum time a script will sleep is one frame (ie, loops contain sleep will run maximum of once per frame). At 20 FPS, sleep 0.01 == sleep 0.05. At sixty FPS your script will run 3x more iterations per second. Modifying the velocity at a rate dependant on iteration time/FPS seems like a reasonable idea to me. You can test scripts at artificially low FPS using the FPS "cheat". Also, since Arma (2?) the script scheduler limits the amount of CPU time spent on scripts, which can cause problems for real time scripts at low FPS. I don't think this applies to this script on it's own, but it may do so if there are many other scripts running at the same time. I believe the onEachFrame command runs script outside of this scheduled environment. Share this post Link to post Share on other sites
xendance 3 Posted September 1, 2013 The game simulation only runs one update per frame, so the minimum time a script will sleep is one frame (ie, loops contain sleep will run maximum of once per frame). At 20 FPS, sleep 0.01 == sleep 0.05. At sixty FPS your script will run 3x more iterations per second. Modifying the velocity at a rate dependant on iteration time/FPS seems like a reasonable idea to me.You can test scripts at artificially low FPS using the FPS "cheat". Also, since Arma (2?) the script scheduler limits the amount of CPU time spent on scripts, which can cause problems for real time scripts at low FPS. I don't think this applies to this script on it's own, but it may do so if there are many other scripts running at the same time. I believe the onEachFrame command runs script outside of this scheduled environment. Does sleep otherwise use a wall-clock time, if the minimum is dependant on the framerate? Share this post Link to post Share on other sites
zapat 56 Posted September 1, 2013 Try to use waituntil { someCode; (_velocity select 2) <= -3 }; And see if issue persist. See: http://killzonekid.com/arma-scripting-tutorials-loops-v2/ and http://killzonekid.com/arma-scripting-tutorials-loops/ for reference Share this post Link to post Share on other sites