2d_and_3d_physics_interpolation.rst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. .. _doc_2d_and_3d_physics_interpolation:
  2. 2D and 3D physics interpolation
  3. ===============================
  4. Generally 2D and 3D physics interpolation work in very similar ways. However, there
  5. are a few differences, which will be described here.
  6. Global versus local interpolation
  7. ---------------------------------
  8. - In 3D, physics interpolation is performed *independently* on the **global
  9. transform** of each 3D instance.
  10. - In 2D by contrast, physics interpolation is performed on the **local transform**
  11. of each 2D instance.
  12. This has some implications:
  13. - In 3D, it is easy to turn interpolation on and off at the level of each ``Node``,
  14. via the :ref:`physics_interpolation_mode<class_Node_property_physics_interpolation_mode>`
  15. property in the Inspector, which can be set to ``On``, ``Off``, or ``Inherited``.
  16. .. figure:: img/physics_interpolation_mode.webp
  17. :align: center
  18. - However this means that in 3D, pivots that occur in the ``SceneTree`` (due to
  19. parent child relationships) can only be interpolated **approximately** over the
  20. physics tick. In most cases this will not matter, but in some situations the
  21. interpolation can look slightly wrong.
  22. - In 2D, interpolated local transforms are passed down to children during
  23. rendering. This means that if a parent has ``physics_interpolation_mode`` set to
  24. ``On``, but the child is set to ``Off``, the child will still be interpolated if
  25. the parent is moving. *Only the child's local transform is uninterpolated.*
  26. Controlling the on / off behavior of 2D nodes therefore requires a little more
  27. thought and planning.
  28. - On the positive side, pivot behavior in the scene tree is perfectly preserved
  29. during interpolation in 2D, which gives super smooth behaviour.
  30. Resetting physics interpolation
  31. -------------------------------
  32. Whenever objects are moved to a completely new position, and interpolation is not
  33. desired (so as to prevent a "streaking" artefact), it is the responsibility of the
  34. user to call ``reset_physics_interpolation()``.
  35. The good news is that in 2D, this is automatically done for you when nodes first
  36. enter the tree. This reduces boiler plate, and reduces the effort required to get
  37. an existing project working.
  38. .. note:: If you move objects *after* adding to the scene tree, you will still need
  39. to call ``reset_physics_interpolation()`` as with 3D.
  40. 2D Particles
  41. ------------
  42. Currently only ``CPUParticles2D`` are supported for physics interpolation in 2D. It
  43. is recommended to use a physics tick rate of at least 20-30 ticks per second to
  44. keep particles looking fluid.
  45. ``Particles2D`` (GPU particles) are not yet interpolated, so for now it is
  46. recommended to convert to ``CPUParticles2D`` (but keep a backup of your
  47. ``Particles2D`` in case we get these working).
  48. Other
  49. -----
  50. - ``get_global_transform_interpolated()`` is currently only available for 3D.
  51. - ``MultiMeshes`` are supported in both 2D and 3D.