Animated weapon Raise

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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
22alpha22
Posts: 308
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Re: Animated weapon Raise

Post by 22alpha22 »

The problem is you're trying to play a raise animation before calling A_Raise, thefore the animation is playing while the weapon's sprite is still below the the screen. A_Raise raises the weapon sprite and when it reaches a certain height, I don't remember exactly, 32 I think, it puts the weapon into the Ready state. If you don't have A_Raise in the Select state, then the weapon won't work properly.

I think the easiest way to have a custom Select state would be to have a blank sprite such as TNT1 in the select state and just let A_Raise do its thing, then when it puts your weapon in the Ready state, play your custom raise animation. At the end of your custom animation, have the weapon go to a new alternate ready state such as Ready.Done, you can name it whatever you want really, the important thing is to redirect every state that would normally go to ready to go to the new alt ready state.

Here is a simple mockup demonstrating a custom raise and lower animation.

Code: Select all

States
{
     Spawn:
          WEAP P -1
          Stop
     Select:
          TNT1 A 1 A_Raise    //Use a blank sprite or frame for the regular raise sequence
          Wait
     Deselect:
          WEAP WXYZ 3    //Play your custom lower sequence before you call A_Lower
          TNT1 A 1 A_Lower    //Use a blank sprite or frame while calling A_Lower
          Wait
     Ready:
          WEAP ABCD 3    //Play you custom raise animation here
          Goto Ready.Done    //Goto the state you will actually be using as a Ready state
     Ready.Done:
          WEAP E 1 A_WeaponReady    //This will be your actual ready state
          Wait
     Fire:
          WEAP F 3 A_FireCGun
          WEAP GHI 3
          WEAP A 0 A_Refire
          Goto Ready.Done    //Goto the state you will actually be using as a Ready state
     Hold:
          WEAP F 3 A_FireCGun
          WEAP GHI 3
          WEAP A 0 A_Refire
          WEAP A 0 A_ClearRefire
          Goto Ready.Done    //Goto the state you will actually be using as a Ready state
     Flash:
          WEAP JK 3 Bright
          Stop
}
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1117
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Animated weapon Raise

Post by Jekyll Grim Payne »

Sir Robin wrote: First issue with my weapons is that the sprites look perfect when I view them in Slade with HUD offsets, but in game they are much lower. I've found that if I put Weapon.YAdjust -32 in the defaults block then they look right in fullscreen but still way too low with a status bar. How to fix that?
Weapon sprites start below the screen when the weapon is selected. If your animation requires that they're fully raised, what you need to do is raise them manually:

Code: Select all

Select:
	TNT1 A 0 A_WeaponOffset(0, 32); //raise instantly
	UWAA ONA 4 A_WeaponReady(WRF_NOFIRE|WRF_NOBOB);
	TNT1 A 0 A_Raise;
	wait;
Deselect:
	UWAA ANO 4 A_WeaponReady(WRF_NOFIRE|WRF_NOBOB);
	TNT1 A 0 A_Lower;
	wait;
Strictly speaking, in my expereience calling A_Raise is not absolutely required if your weapon is already raised to 32 units, but I'd rather keep in in any case.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Animated weapon Raise

Post by Sir Robin »

22alpha22 wrote:I think the easiest way to have a custom Select state would be to have a blank sprite such as TNT1 in the select state and just let A_Raise do its thing, then when it puts your weapon in the Ready state, play your custom raise animation. At the end of your custom animation, have the weapon go to a new alternate ready state such as Ready.Done, you can name it whatever you want really, the important thing is to redirect every state that would normally go to ready to go to the new alt ready state.
That was what Jarewill mentioned earlier in this thread. If it works that's good but I wanted to know about Jekyll Grim Payne's ideas to get everything working in the "proper" states.
Jekyll Grim Payne wrote:Weapon sprites start below the screen when the weapon is selected. If your animation requires that they're fully raised, what you need to do is raise them manually:
Strictly speaking, in my expereience calling A_Raise is not absolutely required if your weapon is already raised to 32 units, but I'd rather keep in in any case.
For some reason the 0,32 offset doesn't work for me, weapon is still too low. Putting it at 0,0 works perfectly. But after raise runs it's back to being too low, so I set it back to 0,0 again at ready. This works for me:

Code: Select all

	Ready:
		UWAA A 1 A_WeaponOffset(0,0);
		TNT1 ] 0 A_WeaponReady;
		Loop;
	Deselect:
		UWAA ANO 4;
		TNT1 ] 0 A_Lower;
		wait;
	Select:
		TNT1 ] 0 A_WeaponOffset(0,0);
		UWAA ONA 4 A_WeaponReady(WRF_NOFIRE|WRF_NOBOB);
		TNT1 ] 0 A_Raise;
		wait;
Since you know weapon animations, could I get you to look at my thread here? I'm trying to come up with a way to run the charge animation backwards when the weapon charge fails.
Ultimate Freedoomer
Posts: 226
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Re: Animated weapon Raise

Post by Ultimate Freedoomer »

I do it like:

Code: Select all

 Select:
    SHTG A 1 A_Raise
    SHTG ABCDCB 4
    Goto Ready
  Ready: //The actual Ready state, make all your other states (such as Fire) go here instead
    SHTG A 1 A_WeaponReady
    Loop
basically calling a raise, than playing the animation.
Post Reply

Return to “Scripting”