• util.TraceHull Crashing
    3 replies, posted
Whenever I try to modify the mins and maxs of a tracehull to account for an angle offset, it seems to crash. I might be missing something obvious, but is there a reason it would crash? [lua] local function MoveOffset(pos, ang) return Vector(pos.x * ang:Right(), pos.y * ang:Forward(), pos.z * ang:Up()) end function ENT:HasValidPlacement(pos) local ang = self:GetAngles() -- it only crashes with I try to use MoveOffset local mins = MoveOffset(self:OBBMins(), ang) local maxs = MoveOffset(self:OBBMaxs(), ang) -- old, working code --local mins = self:OBBMins() --local maxs = self:OBBMaxs() maxs.z = (maxs.z * 0.5) pos = pos + Vector(0, 0, self:OBBMaxs().z * 0.5) local tr = { start = pos, endpos = pos, mins = mins, maxs = maxs, filter = {self, owner} } local hullTrace = util.TraceHull(tr) if hullTrace.HitWorld then return false end return true end[/lua]
Seems like something else is causing the crash: [code]] lua_run print(Entity(1):HasValidPlacement( Entity(1):GetPos() )) > print(Entity(1):HasValidPlacement( Entity(1):GetPos() ))... true ] lua_run print(Entity(1):HasValidPlacement( vector_origin )) > print(Entity(1):HasValidPlacement( vector_origin ))... true ] lua_run print(Entity(1):HasValidPlacement( Vector( 1512, 12421, 10 ) )) > print(Entity(1):HasValidPlacement( Vector( 1512, 12421, 10 ) ))... false [/code] [editline]21st April 2016[/editline] I tried this on the bouncy ball SENT as well with the same results.
It didn't seem to crash when I ran it once, but when I have running continuously in a Think() it does crash. [lua] ENT.Rotation = Angle(270, 0, 0) ENT.Range = 58 function ENT:SetValidPlacement(bool) self:SetDTBool(0, bool) end function ENT:GetValidPlacement() return self:GetDTBool(0) end function ENT:SetRotation(num) self:SetDTFloat(0, num) end function ENT:GetRotation() return self:GetDTFloat(0) end local function MoveOffset(pos, ang) return Vector(pos.x * ang:Right(), pos.y * ang:Forward(), pos.z * ang:Up()) end function ENT:HasValidPlacement(pos) local ang = self:GetAngles() -- it only crashes with I try to use MoveOffset local mins = MoveOffset(self:OBBMins(), ang) local maxs = MoveOffset(self:OBBMaxs(), ang) -- old, working code --local mins = self:OBBMins() --local maxs = self:OBBMaxs() maxs.z = (maxs.z * 0.5) pos = pos + Vector(0, 0, self:OBBMaxs().z * 0.5) local tr = { start = pos, endpos = pos, mins = mins, maxs = maxs, filter = {self, owner} } local hullTrace = util.TraceHull(tr) if hullTrace.HitWorld then return false end return true end function ENT:Think() local owner = self:GetOwner() if (not IsValid(owner)) then return end self:SetRotation(math.NormalizeAngle(owner:GetInfoNum("ent_rotation", 0))) local rotation = self:GetRotation() local eyeangles = owner:EyeAngles() local shootpos = owner:GetShootPos() local tr = util.TraceLine({start = shootpos, endpos = owner:GetPos() + (owner:GetAngles():Forward() * self:OBBMaxs().x) + (owner:GetAimVector() * self.Range), mask = MASK_SOLID, filter = owner}) if tr.HitWorld and (not tr.HitSky) then local rot = self.Rotation eyeangles = tr.HitNormal:Angle() eyeangles:RotateAroundAxis(eyeangles:Right(), rot.pitch) eyeangles:RotateAroundAxis(eyeangles:Up(), rot.yaw) eyeangles:RotateAroundAxis(eyeangles:Forward(), rot.roll) local valid = self:HasValidPlacement(tr.HitPos) self:SetValidPlacement(valid) else self:SetValidPlacement(false) end eyeangles:RotateAroundAxis(eyeangles:Up(), owner:GetAngles().yaw + rotation) local pos, ang = tr.HitPos, eyeangles self:SetPos(pos) self:SetAngles(ang) end[/lua]
I think you might want to slow your think down, that's a lot of expensive work to be done in that hook.
Sorry, you need to Log In to post a reply to this thread.