Need help fixing "SetPredictable(true)" making entity have choppy movement
5 replies, posted
I am scripting an entity that spawns with an initial velocity, but I can't define it in the Initialize function because the velocity is based on a value outside the entity, where I do ents.Create(), which is server side only.
-- cl_init.lua
function ENT:Initialize()
self:SetPredictable(true)
end
If I was to take out the SetPredictable function, in multiplayer, the entity would spawn with no velocity (client side) for a brief moment, and not move at all, then when the client finally receives velocity data from the server, it get's set into motion.
That brief pause goes away when I use SetPredictable, but it introduces choppy motion which is also undesirable.
What I'm really looking for is the best way to have both the client and the server side of the entity initialize their velocities so that in multiplayer there is no brief pauses, but yet I can't do that since ents.Create only works server side.
Could you maybe create the entity but not spawn it till you set the velocity on it first and then spawn it? You may also need to disable motion on it till that point. Just a guess.
Yea, I was actually considering doing something like that, where you don't see the bullet until it starts actually moving.
I'm also going to test out using the SetPredictable function outside the Initialize function so that it's set before it's even spawned, and then setting it to false as it spawned, just so the client side of the entity can get the velocity it needs in the beginning.
like this:
ENT:SetPredictable(true)
function ENT:Initialize()
self:SetPredictable(false)
end
You cannot call any entity functions outside Initialize - that is the first method called on an entity just created.
@code_gs what even causes the brief pause when you spawn an entity, but say the entity is supposed to spawn moving, but for a split second it doesn't move.
I'm testing this on a Peer-to-peer server I started, and my ping is averaging 7, but the delay seems longer than 7 ms.
I've also found that the client side of the entity doesn't use PhysObj, and if you try to use it, it practically makes a clone of your entity, weirdly.
I'm pretty sure it's just network delay - you'll notice it happens with the bugbait and SMG grenades when they spawn.
It takes more than 7ms to network everything since not all of the entity data is sent in one packet.
Yeah, clientside physobjs are broken in GMod.
Sorry, you need to Log In to post a reply to this thread.