ParticleGravity emitter,x#,y#,z#
Parameters
|
emitter - CPU or GPU particle emitter entity x# - constant acceleration along x, in units per second per second y# - constant acceleration along y; negative values pull downwards z# - constant acceleration along z |
Description
|
Applies a constant acceleration to every live particle. Despite the name this is a general force, not just downward pull. Use 0,-9.81,0 for debris and sparks that should arc and fall, a small positive y such as 0,0.4,0 for smoke and embers that should drift upwards, and a sideways value such as 3,0,0 for a wind that pushes rain or leaves across the scene. Changing it while the game runs is a cheap way to make weather feel alive. The acceleration is applied in the simulation space chosen by ParticleSpace. With the default world-space particles it is a world direction, so down stays down no matter how the emitter is turned. With local-space particles it is measured on the emitter's axes and tips with the emitter, which is handy for an effect that lives inside a rolling vehicle. Gravity combines with everything else: ParticleVelocity gives the initial push, ParticleDrag bleeds speed away, and ParticleAttractor adds a pull towards a point. Set all three components to 0 for weightless particles such as stars or magic motes. Gotcha: units are per simulated second squared, and simulated time comes from UpdateWorld. This gravity is completely separate from the Box3D world gravity used by physics bodies - turning particle collision on with ParticleCollision does not make particles inherit the physics world's gravity. Requires Extended mode. See also: ParticleVelocity, ParticleDrag, ParticleAttractor, ParticleSpace, ParticleCollision. |
Example
; ParticleGravity 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 magic fountain spraying motes upwards emitter=CreateParticleEmitter(1000) PositionEntity emitter,0,0.5,0 ParticleEmissionRate emitter,150 ParticleLifetime emitter,2,3 ParticleVelocity emitter,0,3,0,0.5,0.3,0.5 ParticleColor emitter,150,220,255,1,80,120,255,0 ParticleSize emitter,0.1,0.03,0.2 EntityBlend emitter,3 grav_y#=-6 While Not KeyDown(1) ; [ / ] change vertical gravity, Space flips it upside down If KeyDown(26) And grav_y>-20 Then grav_y=grav_y-0.2 If KeyDown(27) And grav_y<20 Then grav_y=grav_y+0.2 If KeyHit(57) Then grav_y=-grav_y ; Constant acceleration applied to every particle ParticleGravity emitter,0,grav_y,0 ; 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 [ / ] : gravity Space: flip Esc: exit" Text 0,20,"ParticleGravity emitter,0,"+grav_y+",0" Flip Wend End
Index