Skip to content

Custom Collisions

szapp edited this page Oct 10, 2019 · 16 revisions

The feature Custom Collisions (GFA_CUSTOM_COLLISIONS) allows to manipulate the collision behavior of projectiles (arrows and bolts) in ranged combat. It can be customized under what circumstances a projectiles bounces off of a surface, gets stuck in it or breaks on impact. Likewise the hit registration on NPCs can be customized to have projectile vanish or bounce off of an NPC armor instead of causing damage and eliciting an AI reaction.

On projectile collision with an NPC or the world, a "config function" is called (GFA_GetCollisionWithNpc or GFA_GetCollisionWithWorld). Based on the arguments passed to the function, you can return one of several possible collision behaviors. In the case of NPCs this will also allow to remove the projectile on impact to prevent damage (e.g. to disable friendly fire).

 

Contents

1.   Constants
    1.1.   GFA_COLL_PRIOR_NPC
    1.2.   GFA_TRIGGER_COLL_FIX
2.   Config Functions
    2.1.   GFA_GetCollisionWithNpc
    2.2.   GFA_GetCollisionWithWorld


Constants

The constants can be found in the file config/settings.d.

GFA_COLL_PRIOR_NPC

Adjust the collision behavior on NPCs on rebound. That means when the projectile already collided with the world and is currently bouncing off. This constant can take values similar to GFA_GetCollisionWithNpc, plus one additional option :

  • -1 : No collision with NPCs after first collision (the projectile flies/falls through any NPC after collision).
  • 0 : No hit registration (no damage), projectile vanishes when hitting an NPC.
  • 1 : Positive hit registration. Gothic default, but awkward and can be abused.
  • 2 : No hit registration (no damage), projectile bounces off.

GFA_TRIGGER_COLL_FIX

When this constant is set to true, the trigger collision fix is applied.
This is a inherent bug in Gothic 2: When shooting a projectile inside a trigger with certain properties, the projectile collides continuously and causes a nerve wrecking sound. Any trigger colliding with a projectile is checked for certain properties to prevent the collision. Triggers that require projectile collision (like the levers on Irdorath) are unaffected and remain intact.
This constant is ignored when using GFA in in Gothic 1.


Config Functions

The configuration of this feature is found in the file config/collisions.d.

GFA_GetCollisionWithNpc

This function is called every time an NPC is hit (positive hit!) by a projectile (arrows and bolts). It can be used to define the collision behavior (or disabling hit registration and damage) on NPCs based on different criteria.

Note: Unlike most other config functions, this function is also called for NPC shooters!

Note: If GFA_TRUE_HITCHANCE is true, this function is called for ALL hits (all hits are positive hits).
          If GFA_TRUE_HITCHANCE is false, this function is called for POSITIVE hits only.

The global variable GFA_ProjectilePtr will contain the pointer to the projectile (oCItem) in question for the duration of the function. Outside of the function this variable will always be reset to zero.

Ideas: 'ineffective' ranged weapons, armor materials immune to arrows, disable friendly-fire, maximum range, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.

func int GFA_GetCollisionWithNpc(C_Npc shooter, C_Npc target, C_Item weapon, int material)
shooter The NPC that shot the projectile.
target The NPC that was hit with the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
material Material of the armor of the target as defined as in Constants.d (MAT_METAL, MAT_WOOD, ...). -1 for no armor equipped.
returns The collision response, see below.
  • DAMAGE : Positive hit registration (projectile is put into inventory if GFA_REUSE_PROJECTILES is used).
  • DEFLECT : No hit registration (no damage), projectile bounces off.
  • DESTROY : No hit registration (no damage), projectile vanishes.
     

GFA_GetCollisionWithWorld

This function is called every time the world (static or vobs) is hit by a projectile (arrows and bolts). It can be used to define the collision behavior for different materials or surface textures.

Note: Unlike most other config functions, this function is also called for NPC shooters!

CAUTION: Unfortunately, all vobs in Gothic 1 belong to the UNDEF material group. With descriptive texture names, however, the material can be retrieved, e.g. (STR_IndexOf(textures, "WOOD") != 1). At the end of this function, there is an elaborate check for all wooden textures in Gothic 1 to compensate for the lack of material groups.

The global variable GFA_ProjectilePtr will contain the pointer to the projectile (oCItem) in question for the duration of the function. Outside of the function this variable will always be reset to zero.

Ideas: projectiles get stuck in wood, always bounce off of metal, sometimes break when hitting stone, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.

func int GFA_GetCollisionWithWorld(C_Npc shooter, C_Item weapon, int materials, string textures)
shooter The NPC that shot the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
materials Bit field for all materials attached to the surface.
textures String containing all texture names of the surface, delimiter: "|".
returns The collision response, see below.
  • DESTROY : Projectile is destroyed on impact.
  • STUCK : Projectile gets stuck in the surface.
  • DEFLECT : Projectile is repelled.