Robloxでスクリプトを利用してDeltaTimeを取得する
DeltaTimeとは
以前のフレーム開始から現在のフレーム開始までの時間の長さ。Robloxでは基本的に30フレーム/秒で実行されるためおおよそ33.333ミリ秒となる(実行環境によって変動あり)。
DeltaTimeを求める
ServerScriptServiceの配下にスクリプトを作成して以下のように編集する

パターン1
waitの引数をそのまま利用する
while true do local deltaTime = wait() print(deltaTime) end
パターン2
独自に計算する
local lastTime local deltaTime while true do -- 現在の時間をキャッシュする lastTime = os.clock() -- 1フレーム待機 wait() -- 1フレーム前の時間の差分からdeltaTimeを計算する deltaTime = os.clock() - lastTime print(deltaTime) end
結果

出力はおおよそ0.033秒(33ミリ秒)になっている
