Blitz3D+ Command Reference

ParticleDrag emitter,drag#

Parameters

emitter - CPU or GPU particle emitter entity

drag# - how quickly speed bleeds away; 0 disables drag. Negative values are treated as 0

Description

Slows particles down over time, like air resistance.

Drag scales each particle's speed down smoothly every step, so particles start fast and settle. It is what separates a puff of smoke, which billows out and then hangs, from a jet of steam, which keeps going. Sparks look far better with a little drag too: they burst out hard and then drift down under gravity instead of flying off screen.

The effect is exponential rather than linear, so the loss is proportional to the current speed. Small values are gentle - around 0.15 gives smoke a lazy slowdown, 0.4 makes a fire plume settle quickly, and 0.5 or more brings magic motes almost to a stop within their lifetime. It never reverses direction and never pushes a particle backwards.

Drag applies to the whole velocity, including whatever ParticleGravity and ParticleAttractor have added, which is why falling debris reaches a terminal speed instead of accelerating forever.

Gotcha: drag works against simulated time, so it depends on UpdateWorld being called at a steady rate like the rest of the simulation. Setting it to 0 does not restore lost speed; it only stops taking more away.

Requires Extended mode.

See also: ParticleVelocity, ParticleGravity, ParticleAttractor, ParticleLifetime, ParticlePreset.

Example

; ParticleDrag Example
; --------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6
CameraClsColor camera,8,12,24

floor=CreatePlane()
EntityColor floor,30,34,44

; Fast sparks shooting out sideways - drag decides how far they fly
emitter=CreateParticleEmitter(1000)
PositionEntity emitter,0,1.5,0
ParticleEmissionRate emitter,200
ParticleLifetime emitter,1.5,2.5
ParticleVelocity emitter,0,1,0,4,2,4
ParticleGravity emitter,0,-2,0
ParticleColor emitter,255,230,150,1,255,120,20,0
ParticleSize emitter,0.08,0.02,0.2
EntityBlend emitter,3

drag#=0.2

While Not KeyDown(1)

    ; [ / ] change the exponential velocity drag (0 disables it)
    If KeyDown(26) And drag>0 Then drag=drag-0.02
    If KeyDown(27) And drag<3 Then drag=drag+0.02
    If drag<0 Then drag=0

    ; Apply the current drag to the emitter
    ParticleDrag emitter,drag

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    ; UpdateWorld also advances the particle simulation
    UpdateWorld
    RenderWorld

    Text 0,0,"Arrow keys: move camera   [ / ] : drag   Esc: exit"
    Text 0,20,"ParticleDrag emitter,"+drag+" (high drag stops sparks quickly)"

    Flip

Wend

End

Index