attractors.rst 8.6 KB

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