How to get physics material from entity?
This code:
[code]
local physobj = Ent:GetPhysicsObject()
print(physobj:GetMaterial())
[/code]
returns this error:
[quote]
Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)
[/quote]
Entity is valid.
It's listed in the wiki, it must be broken.
Just to be safe, are you calling it from the server?
Of course
Looks like the entity doesn't have a valid physics object. Are you initializing it properly?
try something like
[lua]
if ValidEntity(phys) then
phys:SetMaterial("gmod_bouncy")
MsgN( tostring(phys:GetMaterial()) )
else
MsgN("not a valid physobj")
end
[/lua]
if that fails then getmaterial doesn't work for physics objects.
[QUOTE=Rambo_6;16937287]if that fails then getmaterial doesn't work for physics objects[/QUOTE]
It does, his physics object is just null.
print(physobj) returning something like "physobject" - not null
This would be nice, or at least I think I know what it is... where you have a stool or something, that when you look at something, and shoot it, it tells you the material and copies it to the clipboard.
or even more so, a stool that lets you do that, (look at a prop and right click, to save the material), then left click to apply it to another prop, so you aern't limied to the materials list, and it would be simple enough.
[QUOTE=Hardy;16934072]How to get physics material from entity?
This code:
[code]
local physobj = Ent:GetPhysicsObject()
print(physobj:GetMaterial())
[/code]
returns this error:
Entity is valid.[/QUOTE]
You could do:
[code]print(Ent:GetMaterial())[/code]
lua_run:
[code] for k,v in pairs(ents.FindByClass("prop_physics")) do print(v:GetMaterial()) end [/code]
printing empty lines
Entity.GetMaterial returns a string of the material override. If you haven't set the material, it returns an empty string.
The function works, the entity you are referencing doesn't have a valid physics object ( either at all or just when you called it ).
Looking at a models/props_borealis/bluebarrel001.mdl, I run this code:
[code]lua_run print( Entity( 1 ):GetEyeTrace( ).Entity:GetPhysicsObject( ):GetMaterial( ) )[/code]
And get this:
[code]plastic_barrel[/code]
Sorry, you need to Log In to post a reply to this thread.