attractors.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. .. _doc_3d_particles_attractors:
  2. 3D Particle attractors
  3. ----------------------
  4. .. figure:: img/particle_attractor.webp
  5. :alt: Particle attractors
  6. Particle attractors are nodes that apply a force to all particles within their reach. They pull
  7. particles closer or push them away based on the direction of that force. There are three types
  8. of attractors: :ref:`class_GPUParticlesAttractorBox3D`, :ref:`class_GPUParticlesAttractorSphere3D`,
  9. and :ref:`class_GPUParticlesAttractorVectorField3D`. You can instantiate them at runtime and
  10. change their properties from gameplay code; you can even animate and combine them for complex
  11. attraction effects.
  12. .. note::
  13. Particle attractors are not yet implemented for 2D particle systems.
  14. The first thing you have to do if you want to use attractors is enable the ``Attractor Interaction``
  15. property on the ParticleProcessMaterial. Do this for every particle system that needs to react to attractors.
  16. Like most properties in Godot, you can also change this at runtime.
  17. Common properties
  18. ~~~~~~~~~~~~~~~~~
  19. .. figure:: img/particle_attractor_common.webp
  20. :alt: Common particle attractor properties
  21. :align: right
  22. Common attractor properties
  23. There are some properties that you can find on all attractors. They're located in the
  24. ``GPUParticlesAttractor3D`` section in the inspector.
  25. ``Strength`` controls how strong the attractor force is. A positive value pulls particles
  26. closer to the attractor's center, while a negative value pushes them away.
  27. ``Attenuation`` controls the strength falloff within the attractor's influence region. Every
  28. particle attractor has a boundary. Its strength is weakest at the border of this boundary
  29. and strongest at its center. Particles outside of the boundary are not affected by the attractor
  30. at all. The attenuation curve controls how the strength weakens over that distance. A straight
  31. line means that the strength is proportional to the distance: if a particle is halfway
  32. between the boundary and the center, the attractor strength will be half of what it is
  33. at the center. Different curve shapes change how fast particles accelerate towards the
  34. attractor.
  35. .. figure:: img/particle_attractor_curve.webp
  36. :alt: Different attractor attenuation curves
  37. Strength increase variations: constantly over the distance to the attractor (left), fast
  38. at the boundary border and slowly at the center (middle), slowly at the boundary and
  39. fast at the center (right).
  40. The ``Directionality`` property changes the direction towards which particles are pulled.
  41. At a value of ``0.0``, there is no directionality, which means that particles are pulled towards
  42. the attractor's center. At ``1.0``, the attractor is fully directional, which means particles
  43. will be pulled along the attractor's local ``-Z``-axis. You can change the global direction
  44. by rotating the attractor. If ``Strength`` is negative, particles are instead pulled along
  45. the ``+Z``-axis.
  46. .. figure:: img/particle_attractor_direction.webp
  47. :alt: Different attractor directionality values
  48. No directionality (left) vs. full directionality (right). Notice how the particles move along
  49. the attractor's local Z-axis.
  50. The ``Cull Mask`` property controls which particle systems are affected by an attractor based
  51. on each system's :ref:`visibility layers <class_VisualInstance3D>`. A particle system is only
  52. affected by an attractor if at least one of the system's visibility layers is enabled in the
  53. attractor's cull mask.
  54. .. warning::
  55. There is a `known issue <https://github.com/godotengine/godot/issues/61014>`_ with
  56. GPU particle attractors that prevent the cull mask from working properly in Godot 4.0. We will
  57. update the documentation as soon as it is fixed.
  58. Box attractors
  59. ~~~~~~~~~~~~~~
  60. .. figure:: img/particle_attractor_box_entry.webp
  61. :alt: Particle attractor box
  62. :align: right
  63. Box attractor in the node list
  64. Box attractors have a box-shaped influence region. You control their size with the ``Extents``
  65. property. Box extents always measure half of the sides of its bounds, so a value of
  66. ``(X=1.0,Y=1.0,Z=1.0)`` creates a box with an influence region that is 2 meters wide on each side.
  67. To create a box attractor, add a new child node to your scene and select ``GPUParticlesAttractorBox3D``
  68. from the list of available nodes. You can animate the box position or attach it to a
  69. moving node for more dynamic effects.
  70. .. figure:: img/particle_attractor_box.webp
  71. :alt: Box attractor parts particle field
  72. A box attractor with a negative strength value parts a particle field as it moves through it.
  73. Sphere attractors
  74. ~~~~~~~~~~~~~~~~~
  75. .. figure:: img/particle_attractor_sphere_entry.webp
  76. :alt: Particle attractor sphere
  77. :align: right
  78. Sphere attractor in the node list
  79. Sphere attractors have a spherical influence region. You control their size with the ``Radius``
  80. property. While box attractors don't have to be perfect cubes, sphere attractors will always be
  81. spheres: You can't set width independently from height. If you want to use a sphere attractor for
  82. elongated shapes, you have to change its ``Scale`` in the attractor's ``Node3D`` section.
  83. To create a sphere attractor, add a new child node to your scene and select ``GPUParticlesAttractorSphere3D``
  84. from the list of available nodes. You can animate the sphere position or attach it to a
  85. moving node for more dynamic effects.
  86. .. figure:: img/particle_attractor_sphere.webp
  87. :alt: Sphere attractor parts particle field
  88. A sphere attractor with a negative strength value parts a particle field as it moves through it.
  89. Vector field attractors
  90. ~~~~~~~~~~~~~~~~~~~~~~~
  91. .. figure:: img/particle_attractor_vector_entry.webp
  92. :alt: Particle attractor vector field
  93. :align: right
  94. Vector field attractor in the node list
  95. A vector field is a 3D area that contains vectors positioned on a grid. The grid density controls
  96. how many vectors there are and how far they're spread apart. Each vector in a vector field points
  97. in a specific direction. This can be completely random or aligned in a way that forms distinct
  98. patterns and paths.
  99. When particles interact with a vector field, their movement direction changes to match the nearest vector
  100. in the field. As a particle moves closer to the next vector in the field, it changes
  101. direction to match that vector's direction. The particle's speed depends on the vector's length.
  102. Like box attractors, vector field attractors have a box-shaped influence region. You control their size with the ``Extents``
  103. property, where a value of ``(X=1.0,Y=1.0,Z=1.0)`` creates a box with an influence region that is
  104. 2 meters wide on each side. The ``Texture`` property takes a :ref:`3D texture <class_Texture3D>`
  105. where every pixel represents a vector with the pixel's color interpreted as the vector's direction and size.
  106. .. note::
  107. When a texture is used as a vector field, there are two types of conversion you need to be aware of:
  108. 1. The texture coordinates map to the attractor bounds. The image below shows which part of the texture
  109. corresponds to which part of the vector field volume. For example, the bottom half of the texture
  110. affects the top half of the vector field attractor because ``+Y`` points down in the texture UV space,
  111. but up in Godot's world space.
  112. 2. The pixel color values map to direction vectors in space. The image below provides an overview. Since
  113. particles can move in two directions along each axis, the lower half of the color range represents
  114. negative direction values while the upper half represents positive direction values. So a yellow pixel
  115. ``(R=1,G=1,B=0)`` maps to the vector ``(X=1,Y=1,Z=-1)`` while a neutral gray ``(R=0.5,G=0.5,B=0.5)``
  116. results in no movement at all.
  117. .. figure:: img/particle_attractor_vector_mapping.webp
  118. :alt: Mapping from texture to vector field
  119. To create a vector field attractor, add a new child node to your scene and select ``GPUParticlesAttractorVectorField3D``
  120. from the list of available nodes. You can animate the attractor's position or attach it to a
  121. moving node for more dynamic effects.
  122. .. figure:: img/particle_attractor_vector.webp
  123. :alt: Vector field attractor in a field of particles
  124. Two particle systems are affected by the same vector field attractor. :download:`Click here to download the 3D texture <img/particle_vector_field_16x16x16.bmp>`.