Landing States for Monsters when they jump

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!)
Post Reply
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Landing States for Monsters when they jump

Post by Aerosplinter »

I am using A_ChangeVelocity to make my monsters jump, but is there a way to make landing states for the monsters when they land on the floor right after jumping?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Landing States for Monsters when they jump

Post by Matt »

The simplest way I can think of is to have the jump end in a state like this:

Code: Select all

flying:
 SKUL CCDD 1 A_JumpIf(floorz==z,"land");
 loop;
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Landing States for Monsters when they jump

Post by Aerosplinter »

Matt wrote:The simplest way I can think of is to have the jump end in a state like this:

Code: Select all

flying:
 SKUL CCDD 1 A_JumpIf(floorz==z,"land");
 loop; 
Unfortunately, It did not work. The enemy was staying "frozen" in its hopping state even if it landed on the floor.

Here is my code. I used A_CheckFloor, but the results were the same with how I tried to use A_JumpIf(floorz==z,"land").

Code: Select all

Hop:
	ROY4 VVUU 1 A_FaceTarget(3,270)
	TNT1 A 0 A_Playsound("ROYHOP")
	ROY4 R 1
	{
		A_ChangeVelocity(0,0,11);
		A_FaceTarget(3,270);
		A_Recoil(Frandom(-20,-8));
	}
	ROY4 RRRRRRR 1 A_CheckFloor("Land")
	ROY4 RRRRR 1 
	{
		A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);
		A_CheckFloor("Land");
	}
	ROY4 SSSSSSSS 1 
	{
		A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);
		A_CheckFloor("Land");
	}
	ROY4 TTTTT 1 
	{
		A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);
		A_CheckFloor("Land");
	}
	TNT1 A 0 A_Jump(256,"HopContinue")
	Loop
	
	HopContinue:
	ROY4 T 1 
	{
		A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);
		A_CheckFloor("Land");
	}
	Loop
	
	Land:
	ROY4 U 1 A_Playsound("ROYLAND")
	ROY4 U 1 
	ROY4 VWWXX 1
	Goto See
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Landing States for Monsters when they jump

Post by Void Weaver »

If you've tried to use A_JumpIf like as do you use A_CheckFloor inside of anon. function, then it obviously wrong. It should be written like as if|else condition with a some 'return' exits:

Code: Select all

ROY4 RRRRR 1
   {
      A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN); //Don't forget that A_Chase allow to jump out from the current state!
      If(A_CheckFloor("Land")){Return state("Land");}
      Else{Return state("");}
   }
 ROY4 SSSSSSSS 1
   {
      A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);
      If(floorz==z)
          {
             Return state("Land");
          }
      Else
          {
             Return state("");
          }
   }
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Landing States for Monsters when they jump

Post by Aerosplinter »

Void Weaver wrote:If you've tried to use A_JumpIf like as do you use A_CheckFloor inside of anon. function, then it obviously wrong. It should be written like as if|else condition with a some 'return' exits:

Code: Select all

ROY4 RRRRR 1
   {
      A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN); //Don't forget that A_Chase allow to jump out from the current state!
      If(A_CheckFloor("Land")){Return state("Land");}
      Else{Return state("");}
   }
 ROY4 SSSSSSSS 1
   {
      A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);
      If(floorz==z)
          {
             Return state("Land");
          }
      Else
          {
             Return state("");
          }
   }

It finally worked!! However, it does not work on actors, so is there a way for this to work on actors?
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Landing States for Monsters when they jump

Post by Void Weaver »

Because deco hasn't direct way to check what is landing plane is - actor or floor, AFAIK it's possible only via ZScript.

In your case is much logical to make check for -VelZ and once (after flying down after monster jump) it will equal to 0, then landing are happens.
Similar solution for similar question. Something like:

Code: Select all

ROY4 RRRRR 1
   {
     If(VelZ<0){A_Chase("_a_chase_default","_a_chase_default",CHF_DONTMOVE|CHF_DONTTURN);Return state("");}
      Else{Return state("Land");}
   }
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Landing States for Monsters when they jump

Post by Aerosplinter »

I am still wondering if there is another way for this to work for actors, because with "If(VelZ<0)", it immediately goes to the landing state when they jump. There needs to be a clear solution for this...
User avatar
TXTX
Posts: 195
Joined: Thu Sep 12, 2013 5:53 pm
Location: A Hidden Location

Re: Landing States for Monsters when they jump

Post by TXTX »

Had some old code for decorate before I switched to zscript that might work.

Code: Select all

FallState:
RVM4 S 1 A_JumpIf(momz<=0,1)
Wait
RVM4 S 1
RVM4 T 1 A_JumpIf(momz==0||waterlevel>1,"See")
Wait
Try that. Its not as accurate as zscript but it worked for me.
Also the double check is needed since using momz==0 alone can cause them to stop when at the tip of their jump.
User avatar
Aerosplinter
Posts: 98
Joined: Wed Feb 01, 2017 2:14 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Landing States for Monsters when they jump

Post by Aerosplinter »

TXTX wrote:Had some old code for decorate before I switched to zscript that might work.

Code: Select all

FallState:
RVM4 S 1 A_JumpIf(momz<=0,1)
Wait
RVM4 S 1
RVM4 T 1 A_JumpIf(momz==0||waterlevel>1,"See")
Wait
Try that. Its not as accurate as zscript but it worked for me.
Also the double check is needed since using momz==0 alone can cause them to stop when at the tip of their jump.
For your A_JumpIf, does it mean that it goes to the "Land" state as the actor surfaces on the floor?
User avatar
TXTX
Posts: 195
Joined: Thu Sep 12, 2013 5:53 pm
Location: A Hidden Location

Re: Landing States for Monsters when they jump

Post by TXTX »

Aerosplinter wrote:
TXTX wrote:Had some old code for decorate before I switched to zscript that might work.

Code: Select all

FallState:
RVM4 S 1 A_JumpIf(momz<=0,1)
Wait
RVM4 S 1
RVM4 T 1 A_JumpIf(momz==0||waterlevel>1,"See")
Wait
Try that. Its not as accurate as zscript but it worked for me.
Also the double check is needed since using momz==0 alone can cause them to stop when at the tip of their jump.
For your A_JumpIf, does it mean that it goes to the "Land" state as the actor surfaces on the floor?
Yes, the "See" part at the end is the state you want after the monster stops falling. That can be changed to whatever you like. Change it to "Land" if you want to go specifically to that state.
Post Reply

Return to “Scripting”