Skip to content

Tutorials · Particle Effects · Chapter 11

Collision

15 minutes Uses: ParticleEmitter, Collider, TileMap

By the end

  • The rain landing on the roofs and the street and hopping a little: Collision on rain, Bounce 0.15, Friction 0.4
  • The forge’s sparks given the same module: Bounce 0.5, Friction 0.3
  • What counts as solid to a particle, and what Collision costs
On this page

Rain that lands

So far a particle has passed through everything: the rain falls through the roofs, the street and the ground under it, and is gone only when its Lifetime ends. Collision gives an emitter’s particles something to land on. Two numbers say what happens when they do.

  1. Select rain. In its Collision group, tick Collision, and set Bounce to 0.15 and Friction to 0.4.
  2. Select forge_sparks. In its Collision group, tick Collision, and set Bounce to 0.5 and Friction to 0.3.
  3. Press Ctrl+S, and then F5. Watch the roofs and the street, and press F5 again to stop.
rain selected, its Inspector narrowed with the search box, collision, to the Particle Emitter’s Collision group: a Collision row ticked, Bounce 0.15 and Friction 0.40 as sliders; in the Viewport the rain’s Direction arrow and Spread squares stand at the top edge of the town
The rain’s Collision group: ticked, 0.15 and 0.4.
Collision
Whether this emitter’s particles meet the room’s solid things. Unticked, they pass through everything and the room’s solids are never looked at. Ticked, each particle is tested against the solids near it every step, and bounces off one it meets, or stops on it. Tick it on what lands, the rain and the sparks, and leave it off on what does not: smoke, fog and fireflies.
Bounce
How much of its speed into a surface comes back out, from 0 to 1. At 0 a particle sticks where it lands, and at 1 it springs back as fast as it came. A drop that falls at 340 units a second and bounces at 0.15 leaves at about 51, and under Gravity 200 that carries it up by about 6 units: the height is the speed it leaves at, squared, over twice the Gravity. 0.1 to 0.3 suits rain here, and 0.15 is what you set; the sparks have 0.5.
Friction
How much of its speed along a surface a touch takes away, from 0 to 1. At 0 the surface is ice and the particle slides on as fast as it came, and at 1 it stops dead where it lands. 0.4 suits rain here, and 0.3 suits sparks that should skid.
The roofs, the street and the ground under the street at two seconds with no Collision on the rain: streaks fall through the roofs and the houses’ walls, over the cobbles of the street, and on down the dark ground below it, to the bottom of the picture
For comparison, no Collision: the rain falls through the roofs and the street, and on down the window.
The same part of the town with Collision on, as you set it: no streak below the street, and a scatter of small white flecks above the roofs where drops have landed and hopped; the dark ground under the street is empty
Collision on: the rain stops on the roofs and the street, and hops a little.
Close up of three roofs at two seconds with Bounce 0: small white dots resting along the ridges and eaves of the roofs, where drops landed and stayed
Close up, for comparison, Bounce 0: each drop sticks where it lands, a line of dots along the ridges.
The same close up at Bounce 0.15, as you set it: white dashes hanging in the air in a loose row above the roofs, six or so units up, where the drops have hopped, and no dots resting on the ridges
Bounce 0.15: each drop hops a few units and falls again.

What counts as solid

Two kinds of thing stop a particle: every Collider in the room whose Solid is ticked, and every solid tile of a Tile Map with Collision ticked. A Collider with Solid unticked, a detector, lets particles through, as it lets a character through.

The starter’s five roofs, roof_a to roof_e, are Colliders, and each has an Outline of six points traced on the town picture’s own pixels, so that the rain lands on the slates and not on a box. An Outline replaces the Collider’s box. Its points are in units from the node, and its Step of 4 cuts the slanted sides into small boxes four units long, so a drop lands on a staircase that follows the roof. The Viewport draws each roof as its Outline, a thin green line round the slates, brighter on the roof you have selected. It does not draw the Collider’s Size, 64 by 64, which the Outline replaced and which nothing lands on.

roof_b selected, its Inspector narrowed with the search box, collider, to its Collider: Kind Rectangle, Size x 64 and y 64, a Polygon group with Outline of six items, listed as the pairs 192 and 26, 216 and 9, 240 and 8, 250 and 19, 250 and 32, and 192 and 32, then Step 4.00 u, Offset 0 and 0, Solid ticked, One Way unticked, Layer 0, Include Layers and Exclude Layers Nothing, and Material unticked; in the Viewport the Move arrows at the top left of the town, and the second house’s roof outlined in bright green along its six points, with the other four roofs outlined in a fainter green and three orange circles for the attractors from chapter 10
roof_b’s Collider: an Outline of six points, Solid ticked.

The street is a Tile Map. With its Collision ticked its solid tiles are solid to a particle as to a character.

street selected, its Inspector narrowed with the search box, collision, to the Tile Map: one row, Collision, ticked; in the Viewport the Move arrows at the street’s node in the top left corner of the town
The street’s Tile Map: Collision ticked.

The rain and the sparks

The rainValue
Position320, -12
Rate120
Lifetime1.1
Speed340
Direction0.12, 1
Spread0.04
Gravity200
Start Color0.7, 0.82, 0.9, alpha 0.7
End Color0.7, 0.82, 0.9, alpha 0.5
Start Size2
Capacity144
Sort Layer8
Textureraindrop.png
StretchLength Scale 1, Speed Scale 0.012
ShapeLine, Length 720
Collisionticked, Bounce 0.15, Friction 0.4
The forge sparksValue
Position114, 276
Lifetime1.4
Speed110
Direction0.3, -1
Spread0.9
Gravity180
Start Color1, 0.9, 0.6, alpha 1
End Color1, 0.4, 0.1, alpha 0
Start Size4.5
Capacity32
Trail3
Sort Layer4
BlendAdd
Texturespark-sheet.png
Texture SheetColumns 4, Rows 1, First 0, Last 3, Driver Speed, Max 160
Align To Velocityticked
Drag0.6
Size By Speeda curve from 0.6 at 0 to 1.4 at 1
Color By Speeda gradient from 1, 0.35, 0.1 at 0 to 1, 1, 0.9 at 1
Speed Range0, 160
Collisionticked, Bounce 0.5, Friction 0.3

Check it works