Combat Overview
Combat in Railway Nomads will take place between Player controlled Characters and "NPCAnimals" with different "NPCClasses".
At this stage the planned "NPCClasses" are: "Wolf", "Bear" and "Deer", the latter of which will not actually be hostile.
Dealing Damage with Hunting Tools
In order for a Character to cause damage to the Health of an "NPCAnimal" they will need a HuntingTool (Rifle, Bow or Spear). Combat essentially operates under the same rules as other Interactions, with the "NPCAnimals" having a class which inherits from the IInteraction interface which will check if the Character interacting with them has a HuntingTool and subtracting from the "NPCAnimal"'s Health if the requirements are met.
The Interaction using HuntingTools will differ slightly from other Interactions in that it will not require the Character to be directly adjacent to the "NPCAnimal"
.. in order to work. Instead the valid area for an Interaction initiated by a Character to detect an NPCAnimal will be based on a radius with a variable range dependant on the HuntingTool.
When an NPCAnimal is within the radius of the HuntingTool they will be marked as valid on the Player's UI, and when clicked on (or if the TAB key is pressed) will become the CombatTarget for the Character. If there are multiple "NPCAnimals" in range they are put into a list and pressing TAB will iterate through the list accordingly.
Once an NPCAnimal is the CombatTarget for the Character, pressing the Interact input will then run the Interaction algorithm accordingly. If the NPCAnimal is the CombatTarget for a Character and moves out of the valid radius they will be unassigned accordingly.
As with other Interactions the IInteraction on the "NPCAnimal" class will check if the Character is a particular class (Hunter Gatherer) and inflict a different amount of damage to the NPCAnimal accordingly.
Include diagram showing how the radius, target selection and interaction will work
Receiving Damage from "NPCAnimals"
Some "NPCAnimals" such as the "Wolf" or "Bear" will have the ability to inflict damage to the Health of the Characters. Their AI script will use a state machine which will switch them from Patrolling to Chasing if the player moves within a detection radius. Once the NPCAnimal is within an Attack Radius they will switch to an Attacking state and perform a Attack method targeting the Character.
In the case of the "Wolf" this method will interpolate the NPCAnimal towards the closest adjacent gridspace on the opposite side of the target Character. If the Wolf finishes that movement and the Character is still within 1 grid space (adjacent horizontally, vertically or diagonally) then the target Character's TakeDamage method will be called and be passed a value to reduce the Health by. Otherwise no damage will be done.
The "Bear" class will have a smaller Attack Radius. The Attack method on this class will work by displaying a short animation on the Bear sprite, after which if the Character is still adjacent to the Bear their TakeDamage method will be called with a damage value to reduce the Health by.
The intent here will be that the "Bear" is easier to avoid but will cause a higher amount of damage to the Character if they are caught flat footed.
The diagrams below demonstrate the general idea of how these attacks would function, first with the Wolf then with the Bear.
On the left the Wolf is shown in it's starting position, with the red square indicating the 'hurtbox' which would activate during the attack animation. The central red line shows the main movement of the Wolf as it interpolates to it's finishing point on the opposite side of the target.
This attack can occur from any grid space adjacent to a Character as shown in the diagram on the top-right. Essentially, the Wolf will move from either a horizontally, vertically or diagonally adjacent grid space. When moving diagonally it will technically move further, but the interpolation time will remain the same.
In a case where the grid space on the opposite side of the target Character is not clear, the Wolf would instead target a space adjacent to the blocked space, as shown in the bottom-left.
If no spaces are available the Wolf will instead activate the hurtbox and 'bounce' off the target player, returning to it's original grid space after moving halfway to the position of the target Character, as shown in the bottom left.
In order for damage to be inflicted on the Character the hurtbox must intersect them while the Wolf is performing the leaping attacking animation. Testing would be necessary to determine the best size/duration for the hurtbox and speed for the leaping attack in order for Character to have a fair chance at avoiding being hit if they end up adjacent to a Wolf.
The two diagrams to the right show the Bear performing its attack, in which the hurtbox takes a conical shape and moves from right to left in a short arc. The left diagram shows this attack when the Bear is in the vertical adjacent grid space (horizontal would be indistinguishable), and the right diagram in a diagonally adjacent space.
A green hitbox has been placed for the Character for clarity. The Bear would be able to strike the Character from any position, even if the relative model sizes vs grid space sizes may not suggest otherwise.