Global/ParticleEmitter

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (one -> once)
(added simple example)
 
Line 5: Line 5:
 
|Realm=Client
 
|Realm=Client
 
|IsClass=No
 
|IsClass=No
|Name=ParticleEmitter
 
|Parent=Global
 
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 23: Line 21:
 
|type=CLuaEmitter
 
|type=CLuaEmitter
 
|desc=The new particle emitter.
 
|desc=The new particle emitter.
 +
}}
 +
{{Example
 +
|Description=Creates a simple spark particle effect 100 units above where the local player is looking at.
 +
|Code=local tr =  LocalPlayer():GetEyeTrace()
 +
local pos = tr.HitPos + tr.HitNormal * 100 -- The origin position of the effect
 +
 +
local emitter = ParticleEmitter( pos ) -- Particle emitter in this position
 +
 +
for i = 0, 100 do -- Do 100 particles
 +
local part = emitter:Add( "effects/spark", pos ) -- Create a new particle at pos
 +
if ( part ) then
 +
part:SetDieTime( 1 ) -- How long the particle should "live"
 +
 +
part:SetStartAlpha( 255 ) -- Starting alpha of the particle
 +
part:SetEndAlpha( 0 ) -- Particle size at the end if its lifetime
 +
 +
part:SetStartSize( 5 ) -- Starting size
 +
part:SetEndSize( 0 ) -- Size when removed
 +
 +
part:SetGravity( Vector( 0, 0, -250 ) ) -- Gravity of the particle
 +
part:SetVelocity( VectorRand() * 50 ) -- Initial velocity of the particle
 +
end
 +
end
 +
 +
emitter:Finish()
 
}}
 
}}

Latest revision as of 02:18, 4 July 2018

 ParticleEmitter( )

Contents

Description

Creates a new CLuaEmitter.

NOTE

Do not forget to delete the emitter with CLuaEmitter:Finish once you are done with it

Arguments

Vector position

The start position of the emitter.

This is only used to determine particle drawing order for translucent particles.

Arguments

boolean use3D

Whenever to render the particles in 2D or 3D mode.

Returns

CLuaEmitter

The new particle emitter.

Examples

Example

Creates a simple spark particle effect 100 units above where the local player is looking at.

local tr =  LocalPlayer():GetEyeTrace()
local pos = tr.HitPos + tr.HitNormal * 100 -- The origin position of the effect

local emitter = ParticleEmitter( pos ) -- Particle emitter in this position

for i = 0, 100 do -- Do 100 particles
	local part = emitter:Add( "effects/spark", pos ) -- Create a new particle at pos
	if ( part ) then
		part:SetDieTime( 1 ) -- How long the particle should "live"

		part:SetStartAlpha( 255 ) -- Starting alpha of the particle
		part:SetEndAlpha( 0 ) -- Particle size at the end if its lifetime

		part:SetStartSize( 5 ) -- Starting size
		part:SetEndSize( 0 ) -- Size when removed

		part:SetGravity( Vector( 0, 0, -250 ) ) -- Gravity of the particle
		part:SetVelocity( VectorRand() * 50 ) -- Initial velocity of the particle
	end
end

emitter:Finish()


Personal tools
Navigation