Help Timescale changes cause rope to jump around - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Timescale changes cause rope to jump around (/thread-2512.html) |
Timescale changes cause rope to jump around - dasbin - 26-09-2020 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/Time-timeScale.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. RE: Timescale changes cause rope to jump around - josemendez - 26-09-2020 (26-09-2020, 01:28 AM)dasbin Wrote: Is this expected 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. RE: Timescale changes cause rope to jump around - dasbin - 26-09-2020 (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/Time-fixedDeltaTime.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/adjusting-time-fixeddeltatime-by-time-timescale.869491/ https://forum.unity.com/threads/rigidbodies-seem-to-receive-massive-force-when-entering-in-slow-mo.751352/ RE: Timescale changes cause rope to jump around - josemendez - 28-09-2020 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. |