Gluing a GUI Control to a node
Sometimes it is desired to connect a particular GUI Control to a node in the game world, such that it appears to follow that node as it moves around. For example, to connect a chat bubble to a character that is walking around. This page explains how this is accomplished.
Related GUI Control Attributes
There are three GUI Control fields in particular which must be set:
gluedToNode- This is the ID of the node that the GUI Control would be attached to. So in the case of a chat bubble, this would be the ID of the character that the bubble would be connected to.
WorldSpaceOffset- A Vector3 indicating the distance and direction from the target node that the GUI Control should be positioned. Offset is relative to the target node's local origin. The point will be centered horizontally along the bottom border of the control.
FadeDistance- A floating point number indicating the distance at which the GUI Control begins to fade away
For more information on the above three fields, please see their definitions in the section on "GUIControl Base Fields" on the GUIControls page.
Note that a control's position field still affects it when it is glued to a node; the easiest way to center a GUI Control over its target node is to place the offset point in the direct center of the node's bounding box, and lower the control's position by half of its height.
If a collidable asset obscures direct line-of-sight between the active camera and the point (in world space) to which the control is affixed, the control will be hidden. Generally speaking, character nodes and nodes created from prop buckets are not collidable assets.
While the GUI Control will follow its target node through the 3D world, it still resides on the GUI Layers system. This means that it will never appear to be behind an item located in 3D space, nor can it appear partially obscured - it is either completely visible or not at all. It will also not automatically scale based on the distance between the camera and the target node. If this behavior is desired, you should consider using a Billboard GUI, which actually does reside in the 3D world space. That is done with the external function CreateBillboardFromGUIControl, like so:
bb as NodeRef of Class BillboardNode = CreateBillboardFromGUIControl(someControl)
The following code configures a base GUI Control that might be seen above a character when that character is targeted.
baseplate as noderef of class GUIControl = CreateNodeFromPrototype("_panel") baseplate.build = true baseplate.name = "NamePlate" + targetID baseplate.size.x = 195 baseplate.size.y = 36 baseplate.gluedtonode = targetID baseplate.fadeDistance = 2.5 baseplate.defaultStatePresentation.color.a = .0 baseplate.visible = true baseplate.worldspaceoffset.y = .02