Check distance and compare it

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!)

Check distance and compare it

Postby XASSASSINX » Sat Jul 31, 2021 2:05 pm

Good day, my personal addon of a mod has the well know monster on the community, the Kamikazi Guy, he works by using A_Recoil to launch towards you instead of A_Chase, which is a bit passive and makes him turns direction sometimes at random (even with the flag that dissallows this, it's not full on straight chase). Here's the states of him:

Code: Select allExpand view
 
States
  {
  Spawn:
    BKAM A 0 A_StopSoundEx ("soundslot5")
    BKAM AB 10 A_LookEx (0, 0, 0, 1024)
    loop
  Idle:
    BKAM A 0 A_StopSoundEx ("soundslot5")
    BKAM AB 10 A_LookEx (0, 0, 0, 1024)
    BKAM A 0 A_Jump (8, "IdleNoise")
    loop
  IdleNoise:
    BKAM A 0 A_PlaySound ("kamikazi/idle")
    goto Idle
  See:
    BKAM A 0 A_PlaySoundEx ("kamikazi/scream", "soundslot5", 1)
    BKAM A 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
    BKAM B 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
    BKAM C 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
    BKAM D 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
   Loop
  CheckSee:
    BKAM D 0 A_CheckSight ("Navigate")
    goto See
  Navigate:
    BKAM AABBCCDD 2 A_Chase
    goto CheckSee
  Melee:
    BKAM A 0 A_Die
    stop
  Death:
    BMBE M 0 bright A_SpawnItem ("KamikaziDamage", 0, 40)
    BMBE M 0 bright A_Stop
    BMBE M 0 bright A_StopSoundEx ("soundslot5")
    BMBE M 5 bright A_PlaySound ("weapons/rocklx")
    BMBE N 5 bright
    BMBE O 5 A_NoBlocking
    BMBE PQRST 5
    BMBE U -1
    stop
  }
}


The only important part is the "See" state. It constantly checks if the target is on sight, it recoils him towards the player and if close enough, he explodes. but there is a problem, if he is chasing the player and ends up in something of low height, like those MAP01 Doom 2 lamps on the imp area, he will try to chase the player using the A_Recoil method, but will be stuck to the lamp, because he tries to launch himself straight-on a lamp, as he can see the player.
There's a few ways i've thought to implement a fix to this, but i'm a bit at a loss of the decorate expressions or Zscript vars to use. A_CheckProximity could be one, maybe A_JumpIfCloser? Or maybe using Zscript to compare the distance, and if he is not making a distance progress, assume he is stuck and change to the Navigate state.

Sorry if i was a bit wordy, thanks!
XASSASSINX
 
Joined: 20 Dec 2016
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Check distance and compare it

Postby inkoalawetrust » Mon Aug 02, 2021 2:38 am

Since you seem to only be using DECORATE, you could use A_CheckLOF() to fire a raycast at the target or any other pointer, to see if the ray hits something such as a solid obstacle and jump an amount of frames or to another state label like Navigate based on if the ray hits or not.
User avatar
inkoalawetrust
 
Joined: 26 Aug 2019
Discord: inkoalawetrust #9783
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Check distance and compare it

Postby XASSASSINX » Mon Aug 02, 2021 7:08 am

Oh, wish i knew sooner about this function, seems pretty usefull. And about DECORATE, i was using Zscript before i posted this, but it wans't giving any help.
Thanks!! let me see if it works.

EDIT:
Code: Select allExpand view
  See:
    BKAM A 0 A_PlaySoundEx ("kamikazi/scream", "soundslot5", 1)
    BKAM A 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
    BKAM B 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
    BKAM C 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
    BKAM D 2
   TNT1 A 0 A_FaceTarget
   TNT1 A 0 A_Recoil(-4.5)
   TNT1 A 0 A_CheckLOF("See", CLOFF_FROMBASE)
   TNT1 A 0 A_CheckSight("Navigate")
   TNT1 A 0 A_JumpIfCloser(60, "Melee")
  Navigate:
    BKAM AABBCCDDAABBCCDD 2 A_Chase
    goto CheckSee


Here's the final version of it, the raytracer only fires on the last walk cycle, otherwise it gets stuck on the first animation frame. I'm pretty sure i could fix that too with some of the flags, but it works well enough. Thanks!
XASSASSINX
 
Joined: 20 Dec 2016
Location: MURICAA BROTHER! Just kidding, Brazil.


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests