Skip to content

NPC dynamic interaction improvements and fixes#270

Merged
Blixibon merged 9 commits into
mapbase-source:developfrom
Blixibon:mapbase/feature/dynamic-interaction-improvements
Feb 4, 2024
Merged

NPC dynamic interaction improvements and fixes#270
Blixibon merged 9 commits into
mapbase-source:developfrom
Blixibon:mapbase/feature/dynamic-interaction-improvements

Conversation

@Blixibon
Copy link
Copy Markdown
Member

@Blixibon Blixibon commented Jan 3, 2024

This PR adds several improvements and fixes for NPC dynamic interactions, especially for increasing the capabilities of custom ones.


Keyvalues

Dynamic interactions now support the following new keyvalues:

  • angles_max_diff — The maximum difference from angles_relative required in order to perform the interaction. Previously, this was hardcoded as 4, and that will be the default if this keyvalue is not specified.
  • their_sequence, their_activity, etc. — Optional separate sequence or activity names to use on the target NPC, rather than using the same sequence or activity name as the triggering NPC. This allows for interactions between two NPCs which use the same model.
  • related_interactions — Other interactions which should be delayed as well when this interaction runs. Separated by comma, but also supports wildcards.

Better sequence movement handling

Dynamic interaction testing was not designed with sequence walkframe movement (i.e. sequences which literally move the NPC to another location) in mind. This was previously amended with the new end_position keyvalue, but this is not always appropriate and is sometimes unnecessary when the sequence's end position can be calculated through movement. This also did not retroactively apply to existing interactions which may need end position testing.

Now, if the end_position keyvalue is not specified, dynamic interactions will directly test sequence movement before running. This will occur on all interactions with sequence movement, including existing ones, but only a small number of them actually have it. One set of interactions which does have it is the Combine Hunter's interactions with citizens, which sometimes result in the hunter being stuck in walls if there wasn't enough room at their end position. This change will fix that.

The end_position keyvalue is still functional and will override the sequence movement check. It can be used for sequences with different end positions which do not use sequence walkframe movement, or to prevent the sequence movement check from occurring.

Specific NPC hacks

This PR integrates the following minor hacks for HL2 NPCs running dynamic interactions:

  1. Combine soldiers will use a hack to correct weapon position drift when a NPC it can run a dynamic interaction on comes within 128 units. npc_combine_fixed_shootpos can be used to make this fix occur under all cases.
  2. Zombies will not reset their model after their headcrab is removed if they are running a dynamic interaction. This fixes zombies suddenly snapping to another position during interactions in which the headcrab is specifically removed.
  3. NPCs will not reset their interaction partner if they are dead during script cleanup. This is then used by serverside death ragdoll code to disable collisions with the NPC's interaction partner, fixing serverside ragdolls drifting away from the partner after death.

I tried to separate most of these changes into separate commits to make them easier to understand, although the heavily specialized nature of this subject may make it difficult to do a thorough review.


PR Checklist

  • My PR follows all guidelines in the CONTRIBUTING.md file
  • My PR targets a develop branch OR targets another branch with a specific goal in mind

@Blixibon Blixibon marked this pull request as ready for review January 14, 2024 08:16
void SetInteractionCantDie( bool bCantDie ) { m_bCannotDieDuringInteraction = bCantDie; }
bool HasInteractionCantDie( void );
bool HasValidInteractionsOnCurrentEnemy( void );
virtual bool CanStartDynamicInteractionDuringMelee() { return false; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this ever overwritten and does it ever return true? Or is it more for future use?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to use CanStartDynamicInteractionDuringMelee() for some E:Z2-specific changes and I decided to bring it here for general utility purposes in case other mods use custom dynamic interaction AI.

There may be some merit to overriding this function on Combine soldiers, which I did in E:Z2's case, but I'm going to leave that for a future update when I understand the effects and consequences of soldier interactions outside of E:Z2 better.

pRagdoll->CollisionProp()->SetCollisionBounds( mins, maxs );

#ifdef MAPBASE
// If this was a NPC running a dynamic interaction, disable collisions with the interaction partner
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about when the animation is complete? Would this make that NPC never collide with this ragdoll? Could that ever be an issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ragdoll will continue to have collisions disabled with the interaction partner, but I don't think it would be an issue. There is nothing which specifically relies on NPCs colliding with serverside ragdolls.

Copy link
Copy Markdown

@1upD 1upD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I asked a few questions in comments because I want to understand this better, but I don't think any of them are changes that need to be addressed.

@Blixibon Blixibon merged commit 4cea5d1 into mapbase-source:develop Feb 4, 2024
@Blixibon Blixibon deleted the mapbase/feature/dynamic-interaction-improvements branch February 4, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants