# Effect direction?

I’m working on a custom effect and currently I need it to start at the player’s position (that wasn’t hard), but also go into the direction of the player’s eye trace.
Does anyone around here know how I would do that?

This is the effect’s code:
[lua]
function EFFECT:Init( data )
local Pos = data:GetOrigin()

``````local emitter = ParticleEmitter( Pos )

for i = 1,10 do

local particle = emitter:Add( "particles/fire1", Pos + Vector( math.random(1,650),math.random(0,0),math.random(0,0) ) )

if particle == nil then particle = emitter:Add( "particles/fire1", Pos + Vector(   math.random(1,100),math.random(0,0),math.random(0,0) ) ) end

if (particle) then
particle:SetVelocity(Vector(math.random(0,1),math.random(0,2),math.random(0,0)))
particle:SetDieTime(0.75)
particle:SetStartAlpha(255)
particle:SetEndAlpha(0)
particle:SetStartSize(40)
particle:SetEndSize(60)
particle:SetAngles( Angle(180,0,0) )
particle:SetAngleVelocity( Angle(0,0,0) )
particle:SetRoll(math.Rand( 0, 360 ))
particle:SetColor(math.random(255,255),math.random(0,191),math.random(0,0),math.random(255,255))
particle:SetGravity( Vector(0,0,0) )
particle:SetAirResistance(0 )
particle:SetCollide(false)
particle:SetBounce(0)
end
end

emitter:Finish()
``````

end

function EFFECT:Think()
return false
end

function EFFECT:Render()
end
[/lua]

And this is the activation code (its on a swep)

[lua]
function SWEP:PrimaryAttack()
vPoint = self.Owner:GetPos() + Vector(60,0,50)
local effectdata = EffectData()
effectdata:SetOrigin( vPoint )
util.Effect( “test_effect”, effectdata )
end
[/lua]

[editline]29th July 2016[/editline]

Tried this as well, didn’t work either
[lua]
function EFFECT:Init( data )
local Pos = data:GetOrigin()
local Ang = data:GetAngles()

``````local emitter = ParticleEmitter( Pos )

for i = 1,10 do

local particle = emitter:Add( "particles/fire1", Pos + Vector( math.random(1,650),math.random(0,0),math.random(0,0) ) )

if particle == nil then particle = emitter:Add( "particles/fire1", Pos + Vector(   math.random(1,100),math.random(0,0),math.random(0,0) ) ) end

if (particle) then
particle:SetVelocity(Vector(math.random(0,1),math.random(0,2),math.random(0,0)))
particle:SetDieTime(0.75)
particle:SetStartAlpha(255)
particle:SetEndAlpha(0)
particle:SetStartSize(40)
particle:SetEndSize(60)
particle:SetAngles( Ang )
particle:SetAngleVelocity( Angle(0,0,0) )
particle:SetRoll(math.Rand( 0, 360 ))
particle:SetColor(math.random(255,255),math.random(0,191),math.random(0,0),math.random(255,255))
particle:SetGravity( Vector(0,0,0) )
particle:SetAirResistance(0 )
particle:SetCollide(false)
particle:SetBounce(0)
end
end

emitter:Finish()
``````

end

function EFFECT:Think()
return false
end

function EFFECT:Render()
end

function EFFECT:Touch(hit)
if hit:IsPlayer() then hit:Kill() end
end
[/lua]

[lua]
function SWEP:PrimaryAttack()
vPoint = self.Owner:GetPos() + Vector(60,0,50)
local effectdata = EffectData()
effectdata:SetOrigin( vPoint )
effectdata:SetAngles(self.Owner:GetAngles())
util.Effect( “test_effect”, effectdata )
end
[/lua]

Bump

You are giving the particles a random velocity, give them a velocity in the direction you want (based off Ang:Forward())