Enable physics for effect

Is it possible? I have set a model for effect and I can’t enable physics. Wiki has PhysicsCollide hook, but how to enable it for effect?

First off, did you initialize the physics with http://wiki.garrysmod.com/page/Entity/PhysicsInit ?
Second, are you on the dev branch? EFFECT:PhysicsCollide will be added on the next update, but you can use it right now if you opt-in in the dev branch through steam library -> garry’s mod -> right click options -> betas -> select the dev branch from the menu and then close the window.

Oh, that explains everything. Thanks!

[editline]22nd August 2014[/editline]

Well, I’m in dev branch now, but physics still doesn’t work


function EFFECT:Init(data)
	self:SetModel("models/props_borealis/door_wheel001a.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
end

Also self:GetPhysicsObject() gives an error



[ERROR] Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)


Can you try spawning that model serverside ( as a prop mainly ) and then try spawning the effect again? It’s a known issue with the source engine, you can’t initialize a physics object clientside if it wasn’t loaded serverside first.
It’s dumb, I know.
Also you may want to add these two too ( actually I guess setsolid isn’t needed, but you never know )



self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )


Why in some cases it flies unevenly and out of aim angles?
[img_thumb]http://i.imgur.com/Piz02ue.jpg[/img_thumb] [img_thumb]http://i.imgur.com/xFWD1Jb.jpg[/img_thumb]


local ef = EffectData()
	ef:SetOrigin(self.Owner:GetShootPos())
	ef:SetAngles(self.Owner:GetAimVector():Angle())
	util.Effect("effect_test", ef)



function EFFECT:Init(data)
	local ang = data:GetAngles()
	self:SetModel("models/props_c17/oildrum001.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	local phys = self:GetPhysicsObject()
	if IsValid(phys) then
		phys:SetMass(1)
		phys:EnableDrag(false)
		phys:EnableGravity(false)
		phys:SetBuoyancyRatio(0)
		phys:SetVelocity(ang:Forward() *10000)
	end
end

When you create an EffectData() it doesn’t create the entity right away, think of it like a net message, you set the values on it, and then when the effect is actually dispatched with util.Effect, the entity is then created.
Then you have to read the values from the EffectData() and apply them to the EFFECT entity.



function EFFECT:Init( data )
    self:SetPos( data:GetOrigin() )
    self:SetAngles( data:GetAngles() )
    --etc
end


Fixed with this :v:


local ef = EffectData()
	ef:SetEntity(self)
	ef:SetAngles(ang)
	ef:SetOrigin(self.Owner:GetShootPos())
	util.Effect("effect_test", ef)


function EFFECT:Init(data)
	local ownerang = data:GetEntity():GetOwner():GetAimVector():Angle()
	local ang = data:GetAngles()
	local pos = data:GetOrigin()
	
	self:SetModel("models/Items/AR2_Grenade.mdl")
	self:SetAngles(ang)
	self:SetPos(pos)
	self:PhysicsInit(SOLID_VPHYSICS)
	local phys = self:GetPhysicsObject()
	if phys and IsValid(phys) then
		phys:Wake()
		phys:SetMass(1)
		phys:EnableDrag(false)
		phys:EnableGravity(false)	
		phys:SetVelocity(ownerang:Forward() *10000)
	end
end