My CHERUBS freeze when they are too close to the player!?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

My CHERUBS freeze when they are too close to the player!?

Post by Hidden Hands »

I have a problem. I recently scripted my Cherubs to attack with a leap melee. It works reasonably well, though it is still in progress. My issue is however, that when they leap and corner me, they tend to freeze in attack frame.

Here is a video of my monster freezing when trying to melee attack me in a corner.



And here is the monsters code. Any help or advice on how to prevent this please?

Code: Select all

ACTOR Cherub 2009
{
  XScale 0.8
  Health 50
  PainChance 180
  Speed 15
  Radius 10
  Height 40
  Mass 40
  Monster
  +FLOORCLIP
  SeeSound "cherub/sight"
  AttackSound "cherub/melee"
  PainSound "cherub/pain"
  DeathSound "cherub/death"
  ActiveSound "cherub/active"
  Obituary "%o was slashed by a cherub."
  States
  {
  Spawn:
    CHRB AB 10 A_Look
    Loop
  See:
    CHRB AABBCCDD 2 Fast A_Chase
    Loop
  Melee:
    TNT1 A 0 A_JumpIfCloser(200, "JumpAttack")
    CHRB EF 3 Fast A_FaceTarget
    CHRB GG 3 Fast A_SargAttack
    Goto See
  JumpAttack:
    CHRB E 1 A_FaceTarget
    TNT1 A 0 A_JumpIfCloser(50, "Melee")
    TNT1 A 0
    CHRB CD 4 
    TNT1 A 0
    TNT1 A 0 ThrustThingZ(0,25,0,1)
    TNT1 A 0 A_FaceTarget
    TNT1 A 0 A_Recoil (-10)
    TNT1 D 0 
    CHRB E 2
    CHRB F 2
    TNT1 A 0 //A_GiveInventory ("IsJumping")
    TNT1 A 0 A_FaceTarget
    CHRB F 6 
    TNT1 A 0 A_SargAttack
    CHRB G 1
    CHRB GG 2 A_SargAttack
    CHRB G 1
    TNT1 A 0
    Goto See
  Pain:
    CHRB H 2 Fast
    CHRB H 2 Fast A_Pain
    Goto See
  JumpUp:
    CHRB E 8
  JumpDown:
    CHRB F 1 A_CheckFloor ("Land")
    loop
  Land:
    CHRB A 2 A_Stop
    goto See
  Death:
    CHRB I 8
    CHRB J 8 A_Scream
    CHRB K 4
    CHRB L 4 A_NoBlocking
    CHRB M 4
    CHRB N -1
    Stop
  Raise:
    CHRB N 5
    CHRB MLKJI 5
    Goto See
  }
}
Also, how can I make the cherub melee attack me without looking like a constant loop? It needs to behave a little more like its DOOM 3 counterpart.

Thanks in advance.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: My CHERUBS freeze when they are too close to the player!

Post by Apeirogon »

Code: Select all

 Melee:
    TNT1 A 0 A_JumpIfCloser(200, "JumpAttack")
    CHRB EF 3 Fast A_FaceTarget
    CHRB GG 3 Fast A_SargAttack
    Goto See
  JumpAttack:
    CHRB E 1 A_FaceTarget
    TNT1 A 0 A_JumpIfCloser(50, "Melee")
You create loop using jump if closer function.
If you close enough:
This line
A_JumpIfCloser(200, "JumpAttack")
throw monster to state jump attack, where this line
A_JumpIfCloser(50, "Melee")
throw it into melee state, where this line
A_JumpIfCloser(200, "JumpAttack")
throw monster to state jump attack, where this line
A_JumpIfCloser(50, "Melee")
throw it into melee state, where this line
...
You get it.

If you really cant live without this two checks
A_JumpIfCloser(50, "Melee")

A_JumpIfCloser(200, "JumpAttack")
combine them

Code: Select all

 Melee:
    TNT1 A 0 
    {
        if( A_JumpIfCloser(200, "JumpAttack") )
            {
            return state("JumpAttack");
            }
        if( A_JumpIfCloser(200, "CustomMeleeAttack") )
            {
            return state("CustomMeleeAttack");
            }
    return state("");
   }
goto see
This will make two check.
Firstly it check if target closer than 200 doom meters. If it so, it return "true" jump to "jump attack" state.
If no, it continue and check if target closer than 50 doom meters. If target closer than 50, it return "true" and jump to state "Custom Melee Attack".
If even this check dont return true, monster go to see state and try approach close enough to attack.

All you need to do, its define ""Custom Melee Attack" state

Code: Select all

    CustomMeleeAttack:
    CHRB EF 3 Fast A_FaceTarget
    CHRB GG 3 Fast A_SargAttack
    Goto See
Post Reply

Return to “Scripting”