Page 1 of 1

Check distance and compare it

PostPosted: Sat Jul 31, 2021 2:05 pm
by XASSASSINX
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!

Re: Check distance and compare it

PostPosted: Mon Aug 02, 2021 2:38 am
by inkoalawetrust
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.

Re: Check distance and compare it

PostPosted: Mon Aug 02, 2021 7:08 am
by XASSASSINX
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!