3D2D Wordbox moves to the right every time I press E?

Whenever I press E on my entity, the 3D2D wordbox just moves over a couple of inches… There are no umsgs to tell it to do that or anything that should make it do that.



include("shared.lua")


function ENT:Draw()
	self:DrawModel()
	local pos = self:GetPos()
	local ang = self:GetAngles()
	local oWidth = surface.GetTextSize("This moves to the right on E")
	local tAng = ang
	tAng:RotateAroundAxis(tAng:Up(), 90)
	cam.Start3D2D(pos + Vector(0,-10,18), tAng, 0.2)
		draw.WordBox(2, -oWidth*0.5 + 5, -30, "This moves to the right on E", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255, 255))
	cam.End3D2D()
	end


Is my cl_init.
In my init’s use function all thats in there is just arithmetic’s which have nothing at all to do with the clientside code (as you can see). Maybe its got something to do with the fact im using ENT:Draw and I should be using a hook or something?
Any ideas?

What are you even asking? That code has everything to do with clientside runtime. That code wouldn’t even execute on the server, and it’s doing everything exactly as it should, so what’s the issue?

As far as I know theres no clientside code telling the text to move to the right every time I press E:

Set the font with “surface.SetFont(string Font)” before you call surface.GetTextSize(string Text)

Indeed, just in case, you could also find the info about it here: http://wiki.garrysmod.com/page/surface/GetTextSize
Next time read carefuly before using a function.

All fixed! As far as I know it was this that was causing it:



		draw.WordBox(2, -oWidth*0.5 + 5, -30, <-- That bit with the -oWidth*0.5



When I removed the oWidth bit it worked fine.

Honestly; the guys above are right.

Don’t you notice it shaking when the font / text on the right side of the screen shows up?

If you try to get font width information, without setting the font directly before it; it will produce results exactly as described because it accesses the LAST font that was set on screen for the width calculation.

Set the font before grabbing the information.

so:

[lua]// Before surface.GetTextSize, set the FONT
surface.SetFont( “Default” )
local oWidth, oHeight = surface.GetTextSize(“This moves to the right on E”)[/lua]

Try it, it will make the difference.

The reason the owidth removing makes a difference, is because it’s the first GetTextSize variable of 2 that it can return. Set the font before you get the text size for the aforementioned reasons and you’ll see good results!