Blitz3D+ Command Reference

ParticleVelocity emitter,x#,y#,z#[,variation_x#][,variation_y#][,variation_z#]

Parameters

emitter - CPU or GPU particle emitter entity

x# - starting speed along the emitter's x axis, in units per second

y# - starting speed along the emitter's y axis

z# - starting speed along the emitter's z axis

variation_x# (optional) - random spread added to x, from -variation_x to +variation_x; 0 (default)

variation_y# (optional) - random spread added to y; 0 (default)

variation_z# (optional) - random spread added to z; 0 (default)

Description

Sets the starting velocity given to each new particle.

Velocity is measured on the emitter's own axes, so pointing the emitter with RotateEntity aims the effect. That is what makes a jet exhaust, a wall-mounted steam vent or a directional geyser easy: build the effect once with a velocity of 0,0,10 and then just turn the emitter.

The variation values are what make it look natural. Each particle adds an independent random amount between minus and plus the variation on each axis, so 0,4,0 with a variation of 2,1,2 gives a fountain that mostly goes up but fans out as it rises. With no variation every particle follows exactly the same path and the effect looks like a laser beam.

Velocity is only the starting push. ParticleGravity curves the path, ParticleDrag slows it down, ParticleAttractor pulls it around, and ParticleCollision bounces it off the world.

Gotcha: speeds are per simulated second, and the simulation is stepped by UpdateWorld at one 60 Hz tick per default call - so a speed of 10 covers ten units a second only when you update about 60 times a second. Negative variations behave the same as positive ones. Velocity in stretched render mode also sets the streak direction and length.

Requires Extended mode.

See also: ParticleEmitterShape, ParticleGravity, ParticleDrag, ParticleRenderMode, ParticlePreset.

Example

; ParticleVelocity 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 courtyard fountain - initial velocity decides its height and spread
emitter=CreateParticleEmitter(1000)
PositionEntity emitter,0,0.5,0
ParticleEmissionRate emitter,200
ParticleLifetime emitter,1.5,2.5
ParticleGravity emitter,0,-5,0
ParticleColor emitter,150,220,255,1,80,120,255,0
ParticleSize emitter,0.1,0.03,0.2
EntityBlend emitter,3

speed#=4
spread#=0.5

While Not KeyDown(1)

    ; [ / ] change upward speed, Space toggles narrow/wide random spread
    If KeyDown(26) And speed>0.5 Then speed=speed-0.05
    If KeyDown(27) And speed<8 Then speed=speed+0.05
    If KeyHit(57)
        If spread<1 Then spread=2 Else spread=0.5
    EndIf

    ; Base velocity 0,speed,0 with per-axis random variation
    ParticleVelocity emitter,0,speed,0,spread,0.5,spread

    ; 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   [ / ] : jet speed   Space: spread   Esc: exit"
    Text 0,20,"ParticleVelocity emitter,0,"+speed+",0,"+spread+",0.5,"+spread

    Flip

Wend

End

Index