Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Timescale changes cause rope to jump around
#1
Pregunta 
Is this expected behaviour?
I lerp Unity's Timescale over a couple seconds fairly often (when the player changes rooms and the camera is moving, I slow down time).
During this time, any rope that is otherwise just hanging out will curl up and twitch around, then relax again when timescale goes back to 1.
I am not substepping at all.
As per Unity recommendation (https://docs.unity3d.com/ScriptReference...Scale.html), I am changing both timescale and modifying Time.fixedDeltaTime at the same time. My understanding is that omitting the fixedDeltaTime change will cause unpredictable behaviour for anything that happens to read the fixedDeltaTime on the same frame as a timeScale change (which is likely to happen given that timeScale is being lerped over several seconds), so that doesn't seem to be an option - though it does fix the rope's behaviour.
Reply
#2
(26-09-2020, 01:28 AM)dasbin Wrote: Is this expected behaviour?
I lerp Unity's Timescale over a couple seconds fairly often (when the player changes rooms and the camera is moving, I slow down time).
During this time, any rope that is otherwise just hanging out will curl up and twitch around, then relax again when timescale goes back to 1.
I am not substepping at all.
As per Unity recommendation (https://docs.unity3d.com/ScriptReference...Scale.html), I am changing both timescale and modifying Time.fixedDeltaTime at the same time. My understanding is that omitting the fixedDeltaTime change will cause unpredictable behaviour for anything that happens to read the fixedDeltaTime on the same frame as a timeScale change (which is likely to happen given that timeScale is being lerped over several seconds), so that doesn't seem to be an option - though it does fix the rope's behaviour.

Yes, this is somewhat expected behavior: if you reduce the timestep, rope physics will suddenly be much snappier. Not sure about the "curling up" though, that sounds odd: make sure you've not attached the rope inside a collider that's also set up to collide with it (this is a very common mistake that will result in all sorts of weird behavior).

Changing the timestep size of any iterative engine will have a large effect on convergence. In PhysX (Unity) this isn't too noticeable as there's usually few constraints aside from contacts, but in Obi it is really noticeable because there's lots of constraints.

Try leaving Time.fixedDeltaTime alone, only set the timescale. Also make sure your ObiSolver has interpolation enabled to ensure smooth movement when the timestep size is reduced. See the "RopeAndJoints" sample scene, as it also slows down time at runtime.
Reply
#3
(26-09-2020, 02:53 PM)josemendez Wrote: Yes, this is somewhat expected behavior: if you reduce the timestep, rope physics will suddenly be much snappier.

The timestep change itself doesn't seem to cause the weird behaviour, only the adjusting Time.fixedDeltaTime. It's not super clear from Unity docs but I think writing a value to fixedDeltaTime doesn't change the actual timestep, but rather changes the length it reports for that physics step, and they're recommending it be changed at the same time as adjusting the timestep so that it reports the correct physics step time to other scripts if they query it on the same frame that the actual timestep was changed, right?

My concern with omitting the adjustment to fixedDeltaTime is that I have many other things in my game that rely on this value to be accurate. But to be honest I don't totally understand what might happen if it is adjusted vs not. FixedDeltaTime is supposed to report a value that is *relative* to Time.timescale (per: https://docs.unity3d.com/ScriptReference...aTime.html), so if I don't adjust it, it's no longer an accurate value relative to the timescale.

EDIT:
Well, after some more investigation, others seem to agree that the Unity docs are actually wrong on this and fixedDeltaTime should *not* be modified when changing timescale. I guess that clinches it! I've reported the incorrect docs to Unity.

https://forum.unity.com/threads/adjustin...le.869491/
https://forum.unity.com/threads/rigidbod...mo.751352/
Reply
#4
IMHO, It makes no sense changing Time.fixedDeltaTime when adjusting time scale. Changing the physics timestep (fixedDeltaTime) will always result in different physics behavior no matter what physics engine you use (as it affects convergence speed), so this is obviously something to avoid. The right approach would be to use the same timestep regardless of timescale, and interpolate physics state during frames in which physics haven't been updated (enabling solver interpolation in Obi, or rigidbody interpolation in Unity).

Why on earth this is recommended in the Unity docs is beyond me. Huh
Reply