Blitz3D+ Command Reference

ParticleSpace emitter[,world_space]

Parameters

emitter - CPU or GPU particle emitter entity

world_space (optional) - True for world-space particles, False for local-space particles; True (default)

Description

Chooses whether particles live in world space or follow the emitter.

This one setting decides whether a moving emitter leaves a trail. World-space particles are placed into the world when they are born and then forget about the emitter, so a rocket flying past leaves its smoke hanging in the air behind it. That is what you want for exhaust trails, footstep dust, sparks and almost all weather.

Local-space particles keep their positions relative to the emitter, so the whole cloud moves, turns and scales with it. That suits an effect that is part of an object rather than left behind by it: a magic aura around a floating orb, bubbles inside a jar, sparks that must stay attached to a spinning wheel, or a fire effect inside a vehicle cabin that should tip with the vehicle.

The choice also changes what the coordinates in ParticleGravity and ParticleAttractor mean. In world space they are world directions and world positions; in local space they are measured on the emitter's own axes, so gravity tips with the emitter and an attractor at 0,0,0 sits on the emitter itself.

Gotcha: switching space clears every live particle, because the old positions have no sensible meaning in the new space. Set it once when you build the effect rather than toggling it in your main loop. Loading a ParticlePreset also switches the emitter back to world space.

Requires Extended mode.

See also: ParticleGravity, ParticleAttractor, ClearParticles, CreateParticleEmitter, ParticleEmitterShape.

Example

; ParticleSpace Example
; ---------------------
; Requires Extended mode.

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

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

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

; A patrol drone that circles the scene trailing exhaust
drone=CreateSphere()
ScaleEntity drone,0.25,0.25,0.25
EntityColor drone,255,120,60

; Exhaust emitter parented to the drone so it travels along
emitter=CreateParticleEmitter(800,drone)
ParticleEmissionRate emitter,150
ParticleLifetime emitter,1.5,2.5
ParticleVelocity emitter,0,0.5,0,0.2,0.2,0.2
ParticleColor emitter,255,180,80,1,120,120,130,0
ParticleSize emitter,0.12,0.3,0.2
EntityBlend emitter,3

; World space: the trail stays behind where it was emitted
ParticleSpace emitter,True
world_space=True

angle#=0

While Not KeyDown(1)

    ; Space toggles world-space and local-space particles
    If KeyHit(57)
        world_space=Not world_space
        ; Changing space clears the live particles
        ParticleSpace emitter,world_space
    EndIf

    ; Fly the drone in a circle
    angle=angle+1.5
    PositionEntity drone,Cos(angle)*2.5,2,Sin(angle)*2.5

    ; 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   Space: toggle particle space   Esc: exit"
    If world_space Then state$="True (trail is left behind)" Else state$="False (cloud follows the drone)"
    Text 0,20,"ParticleSpace emitter,"+state$

    Flip

Wend

End

Index