Jump to content

Getting bars current slice position


ItHadToComeToThis
 Share

You are about to reply to a thread that has been inactive for 1458 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Okay imagine you have a health bar and to display health you are simply using PRIM_SLICE with the y value of HP / HPMAX.

Is it possible to get the current local position of the end of the health bar after it’s been sliced?. If so, how would I do this. I want to add some fx onto the end of the health bar each time it depletes and need to position a texture prim over the end.

Basic text example as on my phone

Health Bar ==========

Bar Shrinks : =======[FX]

Shrink Again : =====[FX]

Link to comment
Share on other sites

Assuming the HP bar is at link_pos, has size link_size, and uses "slice end" to change the size of the bar...

// link_pos:     =====.=====

vector HP_bar_start = link_pos;
HP_bar_start.z -= link_size.z/2;

// HP_bar_start: .==========

vector slice = llGetLinkPrimitiveParams(link_no,[PRIM_SLICE]);
vector HP_bar_end = HP_bar_start;
HP_bar_end.z += slice.y * link_size.z;

// HP_bar_end: ==========.

Something like that anyway. The basic idea is:

  • To move to the beginning of the HP bar, you have to shift your position by half of the HP bar's length, because the center of the object is halfway through the HP bar.
  • Then you can get the slice value, and use it to move from the beginning of the HP bar.
    • Since the "slice end" value is always between 0 and 1, you have to take the HP bar's actual length into account, if it's longer or shorter than one meter.

Edit: Incidentally I've made some HP bars for games before (and just for fun) and personally I prefer using PRIM_SIZE instead, because PRIM_SLICE is an instant change while scale/position is interpolated client-side.

I think this is similar to what you're trying to do, where the end of the bar has something going on (in this case, it's just an end-cap for a rounded look).

But here's an example of a really simple but nice effects you can do with PRIM_SIZE.

You can even mix the two, like one of my HUDs does. (HP drops with slice, the damage indicator follows with size.)

Edited by Wulfie Reanimator
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1458 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...