Different drawing behaviour when looking at entity.
2 replies, posted
I would have been somewhat satisfied with this code:
[lua]
function ENT:Draw()
local Pos = self:GetPos()
local Ang = self:GetAngles()
local rotAng = Angle(Ang)
self.rotationOffset = (self.rotationOffset + self.rotationSpeed * FrameTime()) % 360
rotAng:RotateAroundAxis(Ang:Up(), self.rotationOffset)
self:SetRenderAngles(rotAng)
self:DrawModel()
self:SetRenderAngles()
local owner = self:Getowning_ent()
owner = (IsValid(owner) and owner:Nick()) or DarkRP.getPhrase("unknown")
local title = DarkRP.getPhrase("tip_jar")
surface.SetFont("HUDNumber5")
local titleTextWidth, titleTextHeight = surface.GetTextSize(title)
local ownerTextWidth = surface.GetTextSize(owner)
Ang:RotateAroundAxis(Ang:Forward(), 90)
cam.Start3D2D(Pos - Ang:Right() * 11.5, Ang, 0.2)
draw.WordBox(2, -titleTextWidth * 0.5, -48 , title, "HUDNumber5", self.colorBackground, self.colorText)
draw.WordBox(2, -ownerTextWidth * 0.5, -48 + titleTextHeight + 4, owner, "HUDNumber5", self.colorBackground, self.colorText)
cam.End3D2D()
end
[/lua]
if it wasn't for the utterly retarded fact that it [B]stops[/B] doing what I programmed it to do the [I]moment[/I] I directly look at the entity:
[vid]http://cdn-e1.streamable.com/video/mp4/6odcw.mp4?token=1485604772_b8ed5f06d0b867e43dcf041357c1b9e976ac4d9a[/vid]
What specific fuckup do I need to work around to fix this?
Could it be to do with a hook that's being called when you look at an entity which has the side effect of running code which interferes with this? If that other code fires continuously, the draw hook might not be being called, or the angle might be being reset (or something).
As a side note, I'm not sure I like the spinning effects in DarkRP, it looks pretty but it's kind of not-very-realistic-looking. That's just my opinion, however.
[QUOTE=ph:lxyz;51669889]it's kind of not-very-realistic-looking[/QUOTE]
The less realistic, the better.
Also, it also happens when the entity [I]moves[/I]. That doesn't seem like drawing hook issue to me.
[editline]14th January 2017[/editline]
The solution is to use a clientside model instead:
[lua]
function ENT:Draw()
local Pos = self:GetPos()
local Ang = self:GetAngles()
local rotAng = Angle(Ang)
self.rotationOffset = (self.rotationOffset + self.rotationSpeed * FrameTime()) % 360
rotAng:RotateAroundAxis(Ang:Up(), self.rotationOffset)
self.csModel:SetPos(Pos)
self.csModel:SetAngles(rotAng)
local owner = self:Getowning_ent()
owner = (IsValid(owner) and owner:Nick()) or DarkRP.getPhrase("unknown")
local title = DarkRP.getPhrase("tip_jar")
surface.SetFont("HUDNumber5")
local titleTextWidth, titleTextHeight = surface.GetTextSize(title)
local ownerTextWidth = surface.GetTextSize(owner)
Ang:RotateAroundAxis(Ang:Forward(), 90)
cam.Start3D2D(Pos - Ang:Right() * 11.5, Ang, 0.2)
draw.WordBox(2, -titleTextWidth * 0.5, -72 , title, "HUDNumber5", self.colorBackground, self.colorText)
draw.WordBox(2, -ownerTextWidth * 0.5, -72 + titleTextHeight + 4, owner, "HUDNumber5", self.colorBackground, self.colorText)
cam.End3D2D()
end
[/lua]
Where self.csModel is defined as follows in the init function:
[lua]
self.csModel = ClientsideModel(self.model)
self:CallOnRemove("csModel", fp{SafeRemoveEntity, self.csModel})
self.csModel:SetModelScale(1.5, 0)[/lua]
[editline]14th January 2017[/editline]
Update: the cause has been found by Zoox: Halos in the base entity:
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/entities/base_gmodentity.lua#L7-L31[/url]
Overriding ENT:Think solves it, though I prefer my own solution because of the lack of jitter when holding the entity with the Physgun.
Sorry, you need to Log In to post a reply to this thread.