Created
September 14, 2019 15:42
-
-
Save nukadelic/c59c09aec4f709e4f4d1b4176c455bdb to your computer and use it in GitHub Desktop.
Test Unity time scale and physics rigidbody jitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// Create a plane and a cube above that plane, attach a rigidbody to the cube & add gravity | |
// drop this script anywhere on the scene and watch the variables in realtime | |
// mess around with timeScale and see the results | |
// toggle the jump checkbox during runtime | |
public class TestTimeScale : MonoBehaviour | |
{ | |
[Space,Space,Range(0.01f, 3f)] | |
public float timeScale = 0.5f; | |
[Header("total time")] | |
public float time = 0; | |
public float fixedTime = 0; | |
public float unscaledTime = 0; | |
public float fixedUnscaledTime = 0; | |
public float timeSinceLevelLoad = 0; | |
[Header("delta time")] | |
public float deltaTime = 0; | |
public float fixedDeltaTime = 0; | |
public float fixedUnscaledDeltaTime = 0; | |
public float smoothDeltaTime = 0; | |
public float unscaledDeltaTime = 0; | |
[Header("physics")] | |
public Rigidbody target = null; | |
public bool jump = false; | |
void Start() | |
{ | |
Time.timeScale = timeScale; | |
} | |
void FixedUpdate() | |
{ | |
fixedTime = Time.fixedTime; | |
fixedDeltaTime = Time.fixedDeltaTime; | |
fixedUnscaledTime = Time.fixedUnscaledTime; | |
fixedUnscaledDeltaTime = Time.fixedUnscaledDeltaTime; | |
moveTarget(); | |
} | |
void Update() | |
{ | |
Time.timeScale = timeScale; | |
time = Time.time; | |
deltaTime = Time.deltaTime; | |
unscaledTime = Time.unscaledTime; | |
smoothDeltaTime = Time.smoothDeltaTime; | |
unscaledDeltaTime = Time.unscaledDeltaTime; | |
timeSinceLevelLoad = Time.timeSinceLevelLoad; | |
} | |
void moveTarget() | |
{ | |
if( jump ) | |
{ | |
if( target != null ) | |
{ | |
Vector3 f = Time.deltaTime * Vector3.up * 300; | |
target.AddForce( f , ForceMode.Impulse ); | |
} | |
jump = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when changing timeScale the following will
change
not change
Note: fixedUnscaledTime will start breaking down when timescale will be near zero