CharacterModel
Base model implementation for character entities, such as players and zombies. It handles common animations including damage tinting and various weapon attack motions.
CharacterModel
Extends ModelEntity.
Properties
| Property | Type | Description |
|---|---|---|
lastDamagedTick | number | Tracks the tick when the entity was last damaged. |
lastDamagedAnimationDone | boolean | Flag indicating if the damage flash animation has completed. |
lastFiringTick | number | Tracks the tick when the entity last fired or attacked. |
lastFiringAnimationDone | boolean | Flag indicating if the firing/attack animation has completed. |
weaponUpdateFunc | Function | A dynamically assigned function that handles the animation logic for the character's weapon. |
Methods
constructor()
function constructor(): voidInitializes the model, setting default values for the animation tracking state variables.
update()
function update(dt: number, user: object): voidUpdates the model every frame. Calls updateDamageTint and executes weaponUpdateFunc if it is defined.
updateDamageTint()
function updateDamageTint(tick: ENTITY_DATA): voidChecks if tick.lastDamagedTick has updated. If so, flashes the base and weapon (if present) sprites red for 100ms to visually indicate taking damage.
updatePunchingWeapon()
function updatePunchingWeapon(punchLengthInMs?: number): FunctionReturns an update function for punching weapons. Animates the weapon's Y-position using a sine wave over the duration of punchLengthInMs.
updateSwingingWeapon()
function updateSwingingWeapon(swingLengthInMs?: number, swingAmplitude?: number): FunctionReturns an update function for swinging weapons. Animates the weapon's rotation using a sine wave over the duration of swingLengthInMs with the specified swingAmplitude.
updateBowWeapon()
function updateBowWeapon(pullLengthInMs?: number): FunctionReturns an update function for bow weapons. Animates the bow's string attachment (assumed to be the first attachment) by modifying its Y-position over the duration of pullLengthInMs.