Difference between revisions of "Creating HUDs"

From Second Life Wiki
Jump to navigation Jump to search
m (Added a note about mesh use in constructing HUDs.)
 
(42 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Help |Glossary=*|BugFixes=*}}
{{TOCright}}


[[Image:Attach HUD.png|frame|Right-click an object in inventory and choose '''Attach to HUD''' > ... to use it as a HUD]]
This article describes how to create your own HUDs. For basic information about HUDs, see [http://community.secondlife.com/t5/English-Knowledge-Base/Heads-up-displays-HUDs/ta-p/700083 Heads-up displays (HUDs)]


== What's a HUD? ==
=== Building and Texturing HUDs ===


'''In Second Life, [[object]]s can be worn on one of the eight HUD (short for [http://en.wikipedia.org/wiki/HUD_%28video_gaming%29 heads-up display]) attachment points). HUDs are essential to understand, since every SL Resident eventually comes across them sooner or later.'''
It is easiest to keep the root prim rotation at <0., 0., 0.> while building. That way, you can know that the west side of the object will be the one facing the screen when attached. For a box prim, that is [[face]] 4.


A HUD typically consists of a control panel with different buttons you can click on to do context-specific stuff. Some HUDs are "passive" and only meant to be looked at, not touched.
Since an update about 2012 ({{JIRA|SH-2646}}), HUD attachments are always rendered as full bright.


While general [[attachment|attachments]] appear on your avatar's body and other Residents can see them, HUDs are only visible to you and have a fixed viewpoint, similar to how they're used in video games and apps. However, the ''effects'' of a HUD, like [[:Category:LSL_Chat|emitted]] chat, can be visible to other Residents and objects.
Prim alpha and texture transparency work as expected. If you want your HUD to be totally transparent, consider making only the front faces that way. The flat projection will keep the other sides hidden, and it will be easier for residents to find the object if accidentally dropped or forgotten on the ground.


Objects specifically designed to be used like that may have "HUD" in their name to tell you where they'll appear, or they may have "(wear me)" in their name.
HUD objects will capture mouse clicks, even on their transparent parts. If you are using a round interface element, a cylinder would not be a bad choice of prim, so it does not use more space than it needs.


== What are HUDs used for? ==
Shiny works on the HUD, this can help to give an almost-3D appearance to some shapes, like spheres or sculpts. Not everybody enables shiny, so textured shading could still be your best bet.


HUDs are used in many kinds of products where information needs to be directly communicated to you. Popular uses:
=== Scripting HUDs ===


* '''[[AO|Animation overrides]]''' - Click buttons to change how your avatar looks when moving. Turn off the AO if animations conflict with sitting on furniture.
Most scripted functionality works with HUDs. They mostly work like any other attachment, but there are some special exceptions. A page with an [[HTML_HUD_Demo]] can be found on this wiki as well.
* '''[[Combat|Combat systems]]''' - See your health, stamina, experience points, and other relevant in-game info. Use special powers (cast spells in an RPG) to attack enemies.
* '''Customizable attachments''' - Click color swatches to change your hair, clothes, shoes, or more exotic accessories like [http://en.wikipedia.org/wiki/Catgirl neko] tail and ears. Make particle effects (like fire and smoke).
* '''Multi-tools''' - Be alerted when other avatars are nearby (including when you want privacy). Eject intruders from your land. Get region performance stats. And many more.


{{KBtip|You can browse and buy many HUDs on the [http://bit.ly/gHFpCI Second Life Marketplace].}}
==== Differences in behavior ====
* If a sound is triggered using [[llPlaySound|llPlaySound()]], only the HUD wearer will hear it. If the land parcel they're over restricts sound entry/exit, the sound will not play.
** If a sound is triggered using [[llTriggerSound|llTriggerSound()]], the wearer and any bystanders will hear it.
* Like with all attachments, [[llSensor|llSensor()]] will not detect the attachment or its wearer.
* Particles do not generally work. Since Viewer 1.23 there is an experimental debug setting '''RenderHUDParticles''' that you can try, but it is incomplete and switched off by default. On very old viewers (before 1.23) HUD particles would show in world, at (0, 0, 0) globally within the region (the southwest corner). <sup>{{Jira|SVC-2396}}</sup>
* [[Glow]] is not supported on HUD attachments. <sup>{{Jira|VWR-3167}}</sup>
* [[llSetText|llSetText()]] is supported, but be aware that the text does not scale with the HUD or screen size, and the text size is under user control. Despite the limitations, some HUD objects use it to great advantage.
* [[Shared Media]] works on the HUD in Viewer 2.2 and later. On earlier 2.x viewers, clicks and audio may not be available.


== Scripting HUDs ==
==== Differences in coordinates ====
[[Image:HUD-center-coordinates 2.jpg|thumb|300px|HUD center coordinates]]
[[Image:300px-HUD-bottomright-coordinates.jpg|thumb|right|300px|HUD bottom right coordinates]]
HUD attachments are rendered with an orthographic projection, meaning that everything looks flat and there is no perspective. The objects are still 3D, and they can move in XYZ space and be rotated.
* The X coordinate moves away from and toward the wearer, a higher number is farther away and can hide a HUD prim behind others. You can use X changes in a single HUD object to reveal and hide buttons, for one example. There is no good way to grab the red X axis with the viewer editor, but scripts do not have this problem.
* Y moves right to left on the screen; a higher number is more to the left.
* Z moves bottom to top on the screen; a higher number is, well, higher up!


Most scripted functionality works with HUDs, with the following exceptions. (The list is not exhaustive!)
In HUD space, 1 meter is the height of the viewer window, ''including'' the menus and tool bar.  The (0,0,0) position depends on the HUD attachment point. For the Center and Center 2 points, zero is the center of the screen. For the four corner HUD points, zero is that corner of the viewer window. Zero for the top and bottom is centered on the window, again hidden behind the menu or toolbar. There is no way provided to learn the ''width'' of the viewer window, or the pixel dimensions. (The [[FindScreenWidth]] script example can return the display width on touch, if the attachment is on one of the corner HUD slots.)


* Particles do not work. Don't have HUD [[prim]]s generate them. If a HUD attempts to generate particles, they appear at <0,0,0> in the current sim, annoying your neighbors.
If '''Move & View''' > '''Automatic position for: Sidebar''' is ''checked'', the HUD coordinates will automatically be scaled to exclude the sidebar when it is open. If this feature is ''unchecked'', the entire window width is used regardless. (Some third-party themes may ignore this setting.)


* If a sound is triggered using [[llPlaySound]](), only the HUD wearer will hear it. If the land parcel they're over restricts sound entry/exit, the sound will not play.
Since standard prim HUD attachments cannot be clicked through even if they're invisible, the common solutions to getting them out of the way are moving, shrinking, or rotating.
** If a sound is triggered using [[llTriggerSound]](), the wearer and any bystanders will hear it.
* The [[Sensor]] will not detect the avatar wearing the HUD.


Scripted movement of HUD pieces is relative to the attachment points. The position vector used by [[llSetPos]]() is interpreted as [DESCRIPTION MISSING!]. A depth of -1 will render in front of a depth of 0.
HUD attachments can be made from mesh in such a way as to have a side that will present no face to the screen when rotated, which allows them to be clicked through. Small buttons can be included in their construction to trigger the rotation.


Since HUD attachments cannot be clicked thru even if they're invisible, the common solutions to getting them out of the way are moving them and shrinking them.
Use [[llGetLocalPos|llGetLocalPos()]] to learn an attachment's position on the screen, [[llSetPos|llSetPos()]] to move it. ([[llGetPos|llGetPos()]] looks tempting, but for attachments that tells us the ''avatar's'' position.)


If you are trying to move the HUD around relative to its current position, use [[llGetLocalPos]]() rather than [[llGetPos]]().
This example moves the HUD away from the wearer, possibly behind other HUD attachments:


example:
<syntaxhighlight lang="lsl2">llSetPos(llGetLocalPos() + (<0.25, 0.0, 0.0> * llGetLocalRot()));</syntaxhighlight>


<lsl>llSetPos(llGetLocalPos() + (<0.25,0,0> * llGetLocalRot()));</lsl>


 
[[Category:Content creation]]
== Solving problems with HUDs ==
 
==== HUD is invisible ====
This problem arises when the person who made the HUD (or gave it to you) has a screen resolution greater than yours: The HUD is attached at the position that it had on their screen, but that is outside your field of view. The solution is:
# Attach another HUD (one that you know works properly for you).
# Right-click it and select "Edit".
# Zoom out until you can see the other HUD.
# Left-click on the stray and move it back within the white rectangle marking your viewer's screen size. '''Note''': use the arrowheads to move the HUD, clicking on the arrows' tails sometimes drops you out of edit mode.
# Close the Edit window to return to normal viewing.
 
This will only bring the HUD back into view temporarily.  Once you close the HUD and reopen it, the problem will repeat itself.
 
 
{{red|clean up!}}
 
In fighter aircraft and first-person shooters, the HUD (or Heads-Up Display) shows the user important information directly in their field of vision. In Second Life, HUD attachment points have been added to the right-click/pie menu and inventory right-click menu for objects you own. To attach an object to your HUD, right-click it, choose 'Attach HUD >' and pick one of the eight attachment points. The object will be attached to your viewer and only you will see it.
 
The biggest advantage to HUD attachment points is that they do not show up in-world as attached to your avatar. Other Residents will not see them. Many applications for this feature can be imagined, including games where you do not want the other players to see what you have; Informational displays such as speedometers, simulator statistics, radars, ammunition remaining, etc. and photo slideshows of your grandmother's visit to the largest ball of cling-wrap in the world. Subjecting others to that should be abuse-report-worthy. Keep them in your HUD!
 
HUD attachments can be scripted to take advantage of LSL, with a few limitations. Particles do not work on HUD attachments. In addition, there are a few known issues with HUD attachments. HUD attachments obscure chat bubbles if they overlap. HUD attachments can not be clicked-through because HUD attachments can receive touch events (by design). HUD attachments only appear in snapshots if you have the 'UI in snapshot' option enabled.

Latest revision as of 16:55, 27 July 2024

This article describes how to create your own HUDs. For basic information about HUDs, see Heads-up displays (HUDs)

Building and Texturing HUDs

It is easiest to keep the root prim rotation at <0., 0., 0.> while building. That way, you can know that the west side of the object will be the one facing the screen when attached. For a box prim, that is face 4.

Since an update about 2012 (SH-2646), HUD attachments are always rendered as full bright.

Prim alpha and texture transparency work as expected. If you want your HUD to be totally transparent, consider making only the front faces that way. The flat projection will keep the other sides hidden, and it will be easier for residents to find the object if accidentally dropped or forgotten on the ground.

HUD objects will capture mouse clicks, even on their transparent parts. If you are using a round interface element, a cylinder would not be a bad choice of prim, so it does not use more space than it needs.

Shiny works on the HUD, this can help to give an almost-3D appearance to some shapes, like spheres or sculpts. Not everybody enables shiny, so textured shading could still be your best bet.

Scripting HUDs

Most scripted functionality works with HUDs. They mostly work like any other attachment, but there are some special exceptions. A page with an HTML_HUD_Demo can be found on this wiki as well.

Differences in behavior

  • If a sound is triggered using llPlaySound(), only the HUD wearer will hear it. If the land parcel they're over restricts sound entry/exit, the sound will not play.
    • If a sound is triggered using llTriggerSound(), the wearer and any bystanders will hear it.
  • Like with all attachments, llSensor() will not detect the attachment or its wearer.
  • Particles do not generally work. Since Viewer 1.23 there is an experimental debug setting RenderHUDParticles that you can try, but it is incomplete and switched off by default. On very old viewers (before 1.23) HUD particles would show in world, at (0, 0, 0) globally within the region (the southwest corner). SVC-2396
  • Glow is not supported on HUD attachments. VWR-3167
  • llSetText() is supported, but be aware that the text does not scale with the HUD or screen size, and the text size is under user control. Despite the limitations, some HUD objects use it to great advantage.
  • Shared Media works on the HUD in Viewer 2.2 and later. On earlier 2.x viewers, clicks and audio may not be available.

Differences in coordinates

HUD center coordinates
HUD bottom right coordinates

HUD attachments are rendered with an orthographic projection, meaning that everything looks flat and there is no perspective. The objects are still 3D, and they can move in XYZ space and be rotated.

  • The X coordinate moves away from and toward the wearer, a higher number is farther away and can hide a HUD prim behind others. You can use X changes in a single HUD object to reveal and hide buttons, for one example. There is no good way to grab the red X axis with the viewer editor, but scripts do not have this problem.
  • Y moves right to left on the screen; a higher number is more to the left.
  • Z moves bottom to top on the screen; a higher number is, well, higher up!

In HUD space, 1 meter is the height of the viewer window, including the menus and tool bar. The (0,0,0) position depends on the HUD attachment point. For the Center and Center 2 points, zero is the center of the screen. For the four corner HUD points, zero is that corner of the viewer window. Zero for the top and bottom is centered on the window, again hidden behind the menu or toolbar. There is no way provided to learn the width of the viewer window, or the pixel dimensions. (The FindScreenWidth script example can return the display width on touch, if the attachment is on one of the corner HUD slots.)

If Move & View > Automatic position for: Sidebar is checked, the HUD coordinates will automatically be scaled to exclude the sidebar when it is open. If this feature is unchecked, the entire window width is used regardless. (Some third-party themes may ignore this setting.)

Since standard prim HUD attachments cannot be clicked through even if they're invisible, the common solutions to getting them out of the way are moving, shrinking, or rotating.

HUD attachments can be made from mesh in such a way as to have a side that will present no face to the screen when rotated, which allows them to be clicked through. Small buttons can be included in their construction to trigger the rotation.

Use llGetLocalPos() to learn an attachment's position on the screen, llSetPos() to move it. (llGetPos() looks tempting, but for attachments that tells us the avatar's position.)

This example moves the HUD away from the wearer, possibly behind other HUD attachments:

llSetPos(llGetLocalPos() + (<0.25, 0.0, 0.0> * llGetLocalRot()));