I'm trying so hard to get the standard physics engine impact sounds working on my scripted entity. Here's the initialization function on the shared file.
function ENT:Initialize()
if (SERVER) then
self:PhysicsInit(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
self:GetPhysicsObject():SetMass(600)
self:GetPhysicsObject():SetMaterial("flesh")
end
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
end
When calling SetMaterial on the server's physobj, it doesn't get networked to the client. I can't network it myself because the client doesn't have a physobj. I don't want to call PhysicsInit on client because that fucks everything up.
What do I do? Is the only solution to call EmitSound in my ENT:PhysicsCollide hook? I don't want to rewrite an engine feature with Lua, that's dumb.
What do you mean with "the client doesn't have a physobj"?
This is what a normal code for an entity should look like (This will just spawn in a normal prop):
function ENT:Initialize()
if(SERVER) then
self:SetModel("models/hunter/blocks/cube05x05x025.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
--You can put the SetMaterial code here
end
end
end
function ENT:Draw()
self:DrawModel()
end
If you're trying to make something that doesn't have a physobj clientside then you would get something that keeps on falling on the ground then repositions itself. (if you do get past the errors that come with it)
If you are sure of what you're doing then you could always override the sound, it's actually pretty easy with GM:EntityEmitSound
I'll try to write something up and update you when I'm done
Client-side physics objects are broken in GMod - most entities only have one server-side.
That's odd? Shouldn't the SetMaterial still work on client if you use it serverside when setting up the physics for the entity? I never enountered problems like these. If that's still a problem then I'm glad I tought ahead of it and made a code to replace the sounds.
It is set server-side, but the client never even sees the physics object. I'll see if I can fix them client-side somehow.
Thank you very much for replying. I posted this on here before without success.
Ubre, thank you for the example. I already have something going with a PhysicsCollide hook that plays sound. The problem is that I shouldn't have to code an engine feature with Lua.
Unless you call PhysicsInit on client, the physobj is nil on client. If you call it both on server and client, you get a prediction mess and physics get very weird.
Isn't it supposed to work as long as the physics is initialized on both the server AND the client?
From what I understand, the client still has a physObj on the client, it's just inaccessible from Lua. Otherwise, how would prediction work? Prediction seems normal when I walk on the object.
Also, physobj:SetMaterial should be networked to the client, right? Otherwise prediction wouldn't work. So why the fuck aren't impact sounds affected?
This says that it needs to be called on client for impact sounds to work, but initializing custom physobj on the client glitches out. My guess is that changing the physics material only properly works for entities that use a model with collisions. In this case I would consider using a model for the collisions, making it invisible and then manually drawing the model you want the entity to look like inside ENT:Draw(). It is a bit cheaty way of doing things, but that is what I can come up with. That or compiling custom models
It says that because I added it yesterday. Recompiling every model in my gamemode and packing it to a gma is not an option I would consider. I'd rather use a PhysicsCollide hook and simulate what the engine would do.
That should do the job, same thing I use for weapon shells, except that's purely clientside. A tip: make sure to add a delay in the PhysicsCollide callback before playing any sounds, as it gets run realy often
This isn't actually helpful, but I did find an old thread where I asked what the deal was with physics objects:
What is up with clientside physics objects?!
Rubat's answer implies that physics objects shouldn't really exist on the client at all (aside from CSEnts I guess). Make of that what you will, I don't think what you want is possible.... And I agree that it's fucked.
GM:ShouldCollide is the only collision related hook that runs on client. That means I'm gonna have to play impact sounds from server. This is a sad day for programmers worldwide.
They should exist shared like other source games - I'm pretty sure they're not in Source because of something garry implemented collision-mesh related.
Sorry, you need to Log In to post a reply to this thread.