• Getting center of model to draw text problem.
    2 replies, posted
I'm having trouble getting the center of the model. I'm trying to draw text into the middle of it. [IMG]http://i40.tinypic.com/15qc935.jpg[/IMG] But somehow it fails badly, [IMG]http://i42.tinypic.com/28jf6tt.jpg[/IMG] The actual code: [lua] function DrawWeaponInfo(ent) local center = ent:LocalToWorld(ent:OBBCenter()) center = center:ToScreen() local text = "[Use Key]" surface.SetFont( "MenuLarge" ) surface.SetDrawColor( 0, 0, 0, 128) w, h = surface.GetTextSize(text) surface.DrawRect( center.x - (w / 2), center.y, w + 3, h + 1 ) draw.DrawText(text, "MenuLarge", center.x + 1, center.y + 1, Color(255, 255, 255, 200), 1) end [/lua] Any idea, what I'm doing wrong? It does it with every E pickable weapon.. Resizing screenshots, hold on... [editline]09:12AM[/editline] Never mind, the bounding box is really bad on the model, I checked with easy snap. Is there any way to get the center of the hitbox of the weapon?
To the computer, the center of the model is the origin. Unfortunately, most of the weapons have their model origin away from the mesh. Your best chance would to adjust for the different props you would be using. (Maybe a case structure?)
Well, I´ve given up on the CS:S weapon models, and just decided to go for Kermite weapon packs. Which worked wonders.
Sorry, you need to Log In to post a reply to this thread.