ZScript-based HUD that "bobs"?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

ZScript-based HUD that "bobs"?

Postby wildweasel » Mon Apr 09, 2018 7:20 pm

So, having seen another of NoozeArts' mech cockpits in Spriting Carnival, I started thinking about cockpits again...specifically, how I might tie one to weapon bobbing, or else concoct some ZScript-powered HUD bobbing. Is there currently a way to hook into the existing view bobbing logic, or has that not been exported to ZScript yet?
User avatar
wildweasel
change o' pace.
Moderator Team Lead
 
Joined: 15 Jul 2003

Re: ZScript-based HUD that "bobs"?

Postby Jimmy » Mon Apr 09, 2018 9:07 pm

I'd check out how Xaser added the meter to the machinegun in Eriguns - that's ZScript magic right there.
User avatar
Jimmy
 
 
 
Joined: 10 Apr 2006
Discord: Jimmy#4100
Twitch ID: JimmySquared
Operating System: Windows 10/8.1/8/201x 64-bit

Re: ZScript-based HUD that "bobs"?

Postby wildweasel » Mon Apr 09, 2018 9:54 pm

Looks like what's going on is some slightly advanced usage of A_Overlay in the weapon code itself, with the bulk of the complexity being how it decides which number to display on which digit. Unless I want to put my HUD into a weapon and contain the entire HUD logic in that single weapon, I might not want to go about it that way.
User avatar
wildweasel
change o' pace.
Moderator Team Lead
 
Joined: 15 Jul 2003

Re: ZScript-based HUD that "bobs"?

Postby Xaser » Mon Apr 09, 2018 11:06 pm

Though the view bobbing hasn't been exposed, it likely wouldn't be directly usable even if it was since the HUD stuff is pretty separate. Your best bet is so try and replicate it in statusbar-land then apply it to the bar by modifying "self.drawoffset" -- 'course, at this point you're dealing with ZScript statusbars, which are quite a bit different than SBARINFO.

I left some super-high-level explanations of how weapon bobbing works here, which includes a relevant source link that may be useful for copy+paste purposes ('cause math sucks). Vague advice, but it may be the best I can give at present.
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript-based HUD that "bobs"?

Postby Matt » Mon Apr 09, 2018 11:21 pm

In the meantime what I've done is to put a counter in the inventory item that the HUD element is contingent on, then place the HUD element depending on the sine and cosine of that counter.

The main problem is that it doesn't really sync up with the weapon bobbing, but I don't think most people really notice.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript-based HUD that "bobs"?

Postby Gutawer » Tue Apr 10, 2018 5:43 am

Code: Select allExpand view
Weapon weap = cplayer.readyWeapon;
Vector2 bobOffset;
if (weap != NULL) {
   double xx[2];
   double yy[2];
   
   for (int i = 0; i < 2; i++) {
      double ang = (weap.bobSpeed * 128 * CVar.getCVar("wbobspeed", cplayer).getFloat() * 35 / Thinker.TICRATE * (level.time - 1 + i)) * (360 / 8192.0);
      
      double bobx = cplayer.bob * weap.bobRangeX * cplayer.mo.viewBob;
      double boby = cplayer.bob * weap.bobRangeY * cplayer.mo.viewBob;
      
      xx[i] = bobx * cos(ang);
      yy[i] = boby * abs(sin(ang));
   }
   
   bobOffset.x = (xx[0] * (1 - ticFrac) + xx[1] * ticFrac);
   bobOffset.y = (yy[0] * (1 - ticFrac) + yy[1] * ticFrac);
}

This code here should be able to emulate bobbing for use in positioning custom elements for a status bar, though it's worth noting that it needs to be used in a function where ticFrac is available (i.e. BaseStatusBar.draw(), or a function called by it where it can be passed as a parameter). It's stripped down compared to the internal gzdoom code, but it should emulate the Normal bobbing style perfectly. To use the bobbing, just modify the BaseStatusBar drawOffset variable, as Xaser mentioned.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest