Blitz3D+ Command Reference

ClearParticleAttractor emitter

Parameters

emitter - CPU or GPU particle emitter entity

Description

Switches off an emitter's attractor.

Since an emitter has no "strength 0" state that removes the force cleanly, this is how you turn a pull off again. Live particles keep whatever speed the attractor already gave them and then carry on under ParticleGravity and ParticleDrag alone, so the swirl unwinds naturally instead of snapping.

That makes it the natural partner to a timed effect. Turn an attractor on while a portal is open and clear it when the portal closes; pull sparkles into a pickup while the player collects it and clear it once the pickup is gone. Calling it on an emitter that never had an attractor is harmless.

Gotcha: this only removes the attractor. It does not clear particles, does not stop emission, and does not touch gravity - use ClearParticles or PauseParticles for those. Loading a ParticlePreset clears the attractor for you as part of its reset.

Requires Extended mode.

See also: ParticleAttractor, ParticleGravity, ParticleDrag, ClearParticles.

Example

; ClearParticleAttractor 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

; A glowing orb marks where the attractor pulls the sparkles
orb=CreateSphere()
ScaleEntity orb,0.2,0.2,0.2
PositionEntity orb,0,3,0
EntityColor orb,120,200,255

; Magic sparkles drifting up from the ground
emitter=CreateParticleEmitter(800)
PositionEntity emitter,0,0.2,0
ParticleEmitterShape emitter,1,4,0.1,4
ParticleEmissionRate emitter,150
ParticleLifetime emitter,2,3
ParticleVelocity emitter,0,1,0,0.3,0.3,0.3
ParticleColor emitter,120,200,255,1,255,255,255,0
ParticleSize emitter,0.08,0.02,0.3
EntityBlend emitter,3

; Start with the orb pulling the sparkles in
ParticleAttractor emitter,0,3,0,6,0.3
attracting=True

While Not KeyDown(1)

    ; Space toggles between the attractor and ClearParticleAttractor
    If KeyHit(57)
        attracting=Not attracting
        If attracting
            ParticleAttractor emitter,0,3,0,6,0.3
        Else
            ; Disable the emitter attractor - sparkles drift free again
            ClearParticleAttractor emitter
        EndIf
    EndIf

    ; 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 attractor   Esc: exit"
    If attracting Then state$="ParticleAttractor active" Else state$="ClearParticleAttractor called"
    Text 0,20,state$+"   Live particles: "+CountParticles(emitter)

    Flip

Wend

End

Index