Setting a material or color to a Entity:PhysicsInitSphere()
4 replies, posted
Is this possible to do? if so, could anyone give me a quick sample on how; any help greatly appreciated!
You mean something like this?
[lua]
function ENT:Initialize()
local d=20 //Diameter
local r=d/2 //Radius
self.Entity:SetModel("models/BarneyHelmet_faceplate.mdl")
self.Entity:SetMaterial("Models/effects/splodearc_sheet")
self.Entity:SetColor(255, 0, 0, 255)
self.Entity:PhysicsInitSphere(r)
self.Entity:SetCollisionBounds(Vector(-r,-r,-r),Vector(r,r,r))
end
// UnTested
[/lua]
Didn't seem to work, it created a physicsinitsphere but the prop was missing and the material wasn't added
Uh, you do realize the Physics model is invisible, right? You'll need to set the world model of your entity to a sphere .mdl (I suggest the helibomb model), apply the material, color, and then scale it appropriately so it matches the radius of PhysicsInitSphere() you created for it.
This should be what theJ89 meant.
[url=http://wiki.garrysmod.com/?title=Entity.SetModel]Entity.SetModel[/url]
[url=http://wiki.garrysmod.com/?title=Entity.SetModelScale]Entity.SetModelScale[/url]
[url=http://wiki.garrysmod.com/?title=Entity.SetMaterial]Entity.SetMaterial[/url]
[url=http://wiki.garrysmod.com/?title=Entity.SetColor]Entity.SetColor[/url]
On serverside:
[lua]
function ENT:Initialize()
local s = 10; -- this is the scale
self.Entity:SetModel("models/combine_helicopter/helicopter_bomb01.mdl") -- we're using the helibomb as it's almost a perfect sphere
self.Entity:SetMaterial("Models/effects/splodearc_sheet") -- you should change this to the material
local d = self.Entity:BoundingRadius() * 2 * s; -- diameter of the sphere
self.Entity:SetColor(255, 0, 0, 255); -- this should be the color
self.Entity:PhysicsInitSphere(d / 2); -- initialize the physics as a sphere
self.Entity:SetCollisionBounds(Vector(-d / 2, -d / 2, -d / 2),Vector(d / 2, d / 2, d / 2)); -- set up the collision bounds
end
[/lua]
On clientside:
[lua]
ENT:Think()
local s = 10; -- this is the scale again - it should be same as on the server
ply:SetModelScale(Vector(s, s, s) -- It wasn't setting properly for me, unless called in the Think-function
end
[/lua]
Yes, it has whitespacing -- click 'view plain' to see it properly. Note that the code is untested.
Sorry, you need to Log In to post a reply to this thread.