General > Off-Topic

Entity height/width in view angle?

(1/4) > >>

JamminR:
Using Lua, how would one go about getting the height and width, in standard _GmodRect_SetPos (,,h,w) format, accounting for various screen resolutions, of a Entity in the HUD?
(if you know of a mod/script/function that has been released, and can provide link to it, please do!)

Gmod Rect uses 0 to 1 for its X/Y co-ordinates, so
Rect_Set(.5,.5 would place the start of the rectangle in the center of the screen, and (.5,.5, .5,.5) where the last two are height/width of rectangle, would make the rectangle fill lower-right quadrant of the users screen.

However, how would I adjust the height/width dynamically depending on how close I am to an ent? Things farther away would have much smaller height/width perspective than closer of course.

------------------------------------------------------
|           |2|                                                          |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
|                                               w                        |
|                                   -|-     |    |                      |
|                                            |  1 | h                   |
|                                            |___|                     |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
------------------------------------------------------

Say 1 and 2 in my 'hud' above are trashcans/barrels,whatever.
I know I can use EntGetPos to grab vectors, but how would I get the h/w they're using of my screen?

Megiddo:
I think that _GModRect_SetEntity and _GModRect_SetEntityOffset are what you're looking for.

Under notes for setentity: "Actually, the rect doesn't technically "hover" over the entity in the game. The command tells the clients its sent to to constantly setpos the floating rect at the position of the entity on the user's screen, or hide it if the entity is not on the user's screen. ".

So I'm not sure if this will make the rect resize automagically based off distance or not, but if it doesn't, you can easily do it yourself.

Let me know how it works out, I was thinking of doing something similar. :P

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version