• Weird clientside behaviour of PhysicsInitConvex.
    3 replies, posted
[vid]http://dl.dropboxusercontent.com/u/4848096/ShareX/2015/04/box.webm[/vid] As shown on the video, whenever I initialize PhysicsInitConvex on clientside, physgun beam stays in ent's original spawn position. And it looks like entity's position and angle displace themself back to spawn values for a second. Another thing is that on clientside, PhysObj becomes invalid after you grab the entity with a gravity gun. Here's the code I used. [CODE]AddCSLuaFile() ENT.Base = "base_anim" ENT.Type = "anim" ENT.Spawnable = true ENT.PrintName = "Convex test" ENT.Author = "" ENT.Contact = "" ENT.Purpose = "" ENT.Instructions = "" ENT.RenderGroup = RENDERGROUP_OPAQUE local function MakeConvexBox(x, y, z, w) return { Vector(0, 0, 0) * w, Vector(x, 0, 0) * w, Vector(x, y, 0) * w, Vector(0, y, 0) * w, Vector(0, 0, z) * w, Vector(x, 0, z) * w, Vector(x, y, z) * w, Vector(0, y, z) * w } end local contab = MakeConvexBox(2, 0.1, 1.2, 50) function ENT:Initialize() self:PhysicsInitConvex(contab) self:SetSolid(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:EnableCustomCollisions(true) self:DrawShadow(false) local phys = self:GetPhysicsObject() if(IsValid(phys)) then phys:Wake() phys:SetMass(100) end if(CLIENT) then hook.Add("HUDPaint", self, function(self) local selfpos = self:GetPos() local selfrot = self:GetAngles() for k, v in pairs(contab) do local vec = Vector() vec:Set(v) vec:Rotate(selfrot) local spos = (selfpos + vec):ToScreen() surface.SetDrawColor(0, 255, 0, 255) surface.DrawRect(spos.x, spos.y, 5, 5) surface.SetFont("Default") surface.SetTextColor(255, 255, 255, 255) surface.SetTextPos(spos.x, spos.y) surface.DrawText(tostring(k)) end end) end end if(CLIENT) then local boxclr = {r=255, g=0, b=0, a=255} function ENT:Draw() cam.Start3D() render.DrawWireframeBox(self:GetPos(), self:GetAngles(), contab[8], contab[2], boxclr, true) cam.End3D() end end[/CODE] How can I fix this?
MDave can help you with this. This is caused by initializing physics on client.
Make the first four lines in Initialize serverside only.
Not initializing those on clientside will cause prediction problems. As you can see on my video after I grab the entity with a gravity gun, the PhysObj seems to be destroyed. And if you try walking on it you will be continuously "falling" through it, which makes it difficult for a player. I found a workaround, by manually setting angle and position of the physics object in CalcAbsolutePosition method, the physgun beam issue seems to disappear. Yet still, there were some problems with the prediction which caused the entity to change its position improperly. Disabling motion (with EnableMotion) in the same function seems to solve that problem. So this code ran on clientside seems to fix it. [code]function ENT:CalcAbsolutePosition(pos, ang) local phys = self:GetPhysicsObject() if(IsValid(phys)) then phys:EnableMotion(false) phys:SetPos(pos) phys:SetAngles(ang) end end[/code] It looks like it's some bug, since it seems to happen with other physics initializers as well. Same with the gravity gun that makes clientside physics object invalid.
Sorry, you need to Log In to post a reply to this thread.