DoodadDestroyable - alexneargarder/Broforce-Docs GitHub Wiki

DoodadDestroyable

Table of Contents

Unity Lifecycle & Setup

Methods

private void FixedUpdate()

Runs burn logic at fixed time intervals. Handles all burning-related mechanics including damage over time, flame particle creation, unit burning propagation, and block burning spread.


protected override void Start()

Initializes the doodad's sprite components and sets up collision states. Gets the sprite component and stores initial sprite pixel dimensions for damage state transitions. Activates pristine colliders and deactivates damaged/destroyed colliders. If SnapToGround is enabled, positions the doodad at ground height + 8 units.


protected override void Update()

Main update loop handling damage delay timing, shaking behavior before falling, and physics for falling objects. Processes shaking animation when about to fall (using sine wave for visual shake), manages gravity-based falling physics with ground collision detection, triggers landing effects when hitting ground, calls crushing logic for units below, and updates position with shake offset. Only processes falling physics when visible to players for performance.


Properties

public bool Falling { get; set; }

Gets whether this doodad is currently falling or shaking before falling. Returns true if the doodad is actively falling due to gravity or is in the pre-fall shaking state.


Fields

public GameObject collidersDamaged

GameObject containing the colliders active when the doodad is in its damaged state. Initially set inactive in Start(), then activated in Hurt() when damage is first taken. Deactivated again in Death() when the doodad is destroyed. This defines the physical collision boundaries for the damaged object, typically different from the pristine state.


public GameObject collidersDestroyed

GameObject containing the colliders active when the doodad is in its destroyed state. Initially set inactive in Start(), then activated in Death() when the doodad is fully destroyed. This defines the physical collision boundaries for the destroyed object, typically allowing units to pass through or over the debris.


public GameObject collidersPristine

GameObject containing the colliders active when the doodad is in its undamaged pristine state. Set active in Start() when initialized, then deactivated when the doodad takes damage (Hurt method) or is destroyed (Death method). This defines the physical collision boundaries for the undamaged object.


public int heightInBlocks = 1

The height of this doodad in blocks (16 pixel units). Used for fire spreading and particle generation across the full height.


public GameObject[] prinstineChildren

Array of child GameObjects that are visible only when the doodad is in its pristine undamaged state. All objects in this array are deactivated when the doodad takes any damage in the Damage method. Used for visual elements like decorations or details that should disappear when damaged.


public bool SnapToGround

When true, automatically positions the doodad on the ground during Start(). Sets Y position to groundHeight + 8 pixels.


public SpriteSM sprite

Reference to the SpriteSM component that handles the visual representation of the doodad. Used to change sprite frames to show damage states (pristine, damaged, destroyed) by adjusting the lowerLeftPixel coordinates. Initialized in Start if not already assigned.


protected float spriteInitialX

The initial X pixel coordinate of the sprite's lower left corner. Stored during Start to serve as the base offset for calculating damaged and destroyed sprite positions. Used with spritePixelWidth or damageOffsetWidth to show different damage states.


protected int spritePixelWidth = 64

The width in pixels of each damage state frame in the sprite sheet. Defaults to 64 pixels. Used to calculate sprite offsets when transitioning between pristine, damaged, and destroyed visual states. Set from sprite.pixelDimensions.x during initialization.


public int widthInBlocks = 1

The width of this doodad in blocks (16 pixel units). Used for ground detection, collapse calculations, and particle generation.


Combat & Damage

Methods

public virtual void Burn(DamageObject damgeObject)

Applies fire damage to the doodad and manages its burning state. For flammable objects, sets burn time to 8 seconds and accumulates burn damage that can trigger collapse. For heatable objects, extends burn time by 0.5 seconds and increments burn damage. For explosive objects, immediately applies damage. The method checks if accumulated burn damage exceeds the collapse threshold and triggers destruction if so.

Parameters:

  • DamageObject damgeObject: The damage object containing fire damage information and damage amount to apply

protected int BurnCollapsePoint()

Calculates the burn damage threshold at which a burning doodad will collapse. Returns the doodad's maximum health multiplied by 3, meaning the doodad can accumulate burn damage up to three times its health before collapsing from fire damage.

Returns:

  • int: The burn damage value that will trigger a collapse (health * 3)

protected virtual void CreateBloodOnDeath()

Creates red blood particle effects when the doodad dies. This virtual method spawns 20 blood particles at the doodad's position with the particle velocity influenced by the object's current movement (xI, yI). Typically overridden in derived classes to customize the blood effect appearance or behavior.


protected virtual void CreateExplosion()

Creates an explosion effect when the doodad is destroyed. This method generates a visual explosion centered on the doodad with size based on its width and height, burns units within a 64-unit radius, deals explosive damage to units within 48 horizontal and 32 vertical units (dealing 12 damage with 200 horizontal and 300 vertical knockback), and disturbs wildlife within a 130-unit radius. This is typically called when willExplode is true during the death sequence.


private void CreateFlames(Vector3 direction)

Creates flame visual effects across the entire surface of the burning doodad. Spawns flames at each block position (16x16 units) that the doodad occupies, with the flame positions offset by the provided direction vector and the burningFlamesScatterDistance for visual variation.

Parameters:

  • Vector3 direction: Random direction offset to scatter the flame positions for more realistic fire effects

protected virtual void CreateLeafBurstDamaged()

Creates a small leaf particle effect when vegetation doodads are damaged. Generates 20 leaves spreading from the center with minimal upward velocity (5 units + 30% of downward velocity) and slight horizontal spread based on current X velocity.


protected virtual void CreateLeafBurstDeath()

Creates a large leaf particle effect when vegetation doodads are destroyed. Generates leaves with no initial spread but significant upward velocity (50 units + 30% of current Y velocity) and horizontal velocity based on 30% of current X velocity.


protected virtual void CreateWoodParticleBurst()

Creates wood debris particles when wooden doodads are destroyed. Generates 24 wood fragments spreading from the center with upward velocity between 0-140 units and random rotation, contained within the doodad's width.


public override bool Damage(DamageObject damageObject)

Processes damage to the doodad and manages state transitions. Handles alien blood effects if configured, scorches the sprite for fire damage, manages health reduction and damage states (pristine → damaged → destroyed), triggers burning for flammable objects when hit by fire, initiates falling if fallOnReceivingAnyDamage is set, and collapses chain anchors. Returns true if the damage resulted in death.

Parameters:

  • DamageObject damageObject: The damage information including amount, type, and force direction

Returns:

  • bool: True if the doodad was destroyed, false otherwise

public override bool DamageOptional(DamageObject damageObject, ref bool showBulletHit)

Optional damage entry point that always shows bullet hit effects. Clears the waitForDamageToFall flag and delegates to the main Damage method. Always sets showBulletHit to true.

Parameters:

  • DamageObject damageObject: The damage information including amount, type, and force direction
  • out bool showBulletHit: Always set to true to display bullet impact effects

Returns:

  • bool: True if the damage was processed, false otherwise

public override void Death()

Handles the complete destruction of the doodad. Marks as dead and registers with game systems, deactivates pristine/damaged colliders and activates destroyed colliders, disables main collider, limits burn time to 0.4 seconds, initiates falling if canFall is true, creates death effects (particles, explosions, etc.), triggers collapse of doodads above, and either changes sprite to destroyed state or deactivates the GameObject based on configuration.


protected virtual void Hurt()

Transitions the doodad from pristine to damaged state. Changes the sprite offset to show damage visuals (shifts sprite by damageOffsetWidth or spritePixelWidth), creates damage particle effects, swaps collider sets from pristine to damaged, and marks the doodad as damaged. Called when health drops below death threshold but above zero.


protected virtual void MakeEffectsDamaged()

Creates visual effects when the doodad is damaged but not destroyed. Generates effects based on lastDamageObject force values including leaf bursts for tree-type doodads, blood effects if createBloodOnDeath is enabled, and glass shards with force-based velocities if createGlassFragmentsOnDeath is enabled.


protected virtual void MakeEffectsDeath()

Creates comprehensive visual and audio effects when the doodad is destroyed. Disables colliders, drops gibs if configured, creates material-specific particles (wood, metal, barbed wire), handles explosion effects if willExplode is true (including blast damage and unit burning), creates sparks and glass fragments with physics, generates leaf bursts for vegetation, creates blood effects, and disturbs nearby wildlife. Effect intensity varies based on damage force.


private void RunBurnLogic()

Executes the burning logic for flammable, heatable, or explosive doodads during FixedUpdate. For flammable objects, it decrements burn time, creates flame effects at regular intervals, burns nearby units and blocks, and triggers damage when burn time expires. For heatable objects, it gradually reduces burn damage and spreads fire to adjacent blocks. For explosive objects, it immediately triggers damage. The burn damage accumulates and can cause the doodad to collapse when reaching the burn collapse point.


public virtual void SetAlight_Local()

Sets a flammable doodad on fire locally without networking. If the doodad is not dead and is flammable, sets the burn time to 8 seconds and ensures burn damage is at least 1 to start the burning process. This method is typically called by environmental fire spreading mechanics.


Fields

public bool acceptDamageCalls = true

Controls whether this doodad can receive damage. When false, Damage() returns immediately without processing.


public float burnCounter

Timer for spreading fire to surrounding blocks. Triggers block burning every 3 seconds while the doodad burns.


public int burnDamage

Accumulated fire damage that increases while burning. When it exceeds BurnCollapsePoint() (health * 3), triggers destruction.


public float burningFlamesScatterDistance = 6f

Maximum random offset for flame particle positions in pixels. Creates visual variation in fire effects. Default is 6 pixels.


public float burnTime

Remaining burn duration in seconds. While positive, the doodad burns with fire effects and damage spreading.


public float burnUnitsCounter

Timer for burning nearby units. Triggers unit burning every 0.25 seconds while the doodad burns.


public bool cannotBeTotallyDestroyed

Unused field. May have been intended to prevent complete destruction, but has no implementation in the code.


public bool changeSpriteToShowDamage = true

Determines whether the sprite visual should change to show damage states. When true (default), the sprite's lowerLeftPixel is adjusted to show damaged or destroyed frames when the doodad takes damage. Set to false for doodads that don't have damage state sprites.


public bool createBarbedWireParticlesOnDeath

When true, creates barbed wire particle effects when the doodad is destroyed. Spawns 15 barbed wire particles scattered across the doodad's dimensions with upward velocity and random rotation.


public bool createBloodOnDeath

When true, creates blood particle effects when the doodad is damaged, destroyed, or collapses. Calls the CreateBloodOnDeath method to spawn red blood particles. Used for organic or gore-themed destructibles.


public bool createGlassFragmentsOnDeath = true

When true (default), creates glass shard particle effects when the doodad is damaged or destroyed. The number and velocity of shards varies based on whether the doodad explodes (14 shards with high velocity) or is normally destroyed (24 shards).


public bool CreateLeavesOnDeath

When true, creates leaf burst particle effects when the doodad is damaged or destroyed. Calls CreateLeafBurstDamaged on damage and CreateLeafBurstDeath on destruction, with different particle velocities for each state.


public bool createmetalParticlesOnDeath

When true, creates metal particle effects when the doodad is destroyed. Spawns 24 metal particles scattered across the doodad's width and height with upward velocity between 0-140 units and random rotation.


public bool createSandParticlesOnFall

When true, creates sand particle effects when the doodad lands after falling. Spawns 30 sand particles at the landing position with horizontal spread of 48 units and minimal upward velocity (40 units).


public bool createSparksOnDeath

When true, creates spark particle effects when the doodad is destroyed. Spawns 30 spark particles scattered across half the doodad's width with short lifespans (0.25-0.3 seconds). Also checked during plasma bolt ground impacts.


public bool createWoodParticlesOnDeath

When true, creates wood particle effects when the doodad is destroyed. Triggers CreateWoodParticleBurst method which spawns 24 wood particles with similar physics to metal particles. Used for wooden destructible objects.


public float damageOffsetWidth

Custom pixel offset width for damage state transitions. When non-zero, this value is used instead of spritePixelWidth to calculate the sprite offset for damaged and destroyed states. Allows fine-tuning of sprite positioning for non-standard sprite sheets.


public bool deregisterDoodadOnDeath = true

When true, removes this doodad from the map's destroyable doodad list upon death. Default is true.


public bool destroyOnDeath

When true, the sprite's lower left pixel is shifted to show the destroyed sprite variant in Death(). When false (default behavior), the doodad remains visible after death. This does not actually destroy the GameObject - use disableOnDeath (inherited) for that behavior.


public bool explosive

When true, fire damage immediately triggers a damage call instead of starting a burn. Used for volatile objects.


public bool fallOnReceivingAnyDamage

When true, causes the doodad to start falling immediately upon taking any damage. Checked in Damage() method - if true, collapses any attached chain anchor and calls StartFalling(false). Used for precariously balanced objects.


public bool flamable

Determines if this doodad can catch fire when damaged by fire. Enables full burning behavior with spreading and flame effects.


public float flameCounter

Timer for creating visual flame particles. Generates flame effects approximately every 0.05 seconds while burning.


public bool heatable

Allows the doodad to heat up from fire damage without actually burning. Used for metal objects that conduct heat.


protected bool isDamaged

Protected flag indicating whether this doodad has taken damage but is not yet destroyed. Set to true in Hurt() when first damaged, and checked in SubMergesUnit() to determine if units should merge with this object. When true, prevents unit merging.


public bool makeAlienBloodOnHit

When true, creates green alien blood effects when the doodad takes damage. Used for organic alien structures.


private float scorchDamage = 1f

Controls sprite darkening when tintScorchedSprite is true. Starts at 1.0 (no tint) and decreases with fire damage.


public float screenShakeAmountOnFall = 0.3f

The intensity of screen shake when this doodad hits the ground after falling. Default value is 0.3. Passed to SortOfFollow.Shake() in the Land() method. Higher values create more dramatic impact effects when heavy objects hit the ground.


protected bool settled = true

Indicates whether the doodad has settled after falling or is stable. Defaults to true. Set to false when the doodad begins falling or shaking. Reset to true when the doodad lands and comes to rest. Used to prevent redundant fall initiation.


public bool shakeBeforeFalling = true

Determines whether the doodad should shake for 0.3 seconds before falling. When true (default), adds a visual warning before the doodad falls. The shake is triggered when falling conditions are met but the doodad is still settled.


protected float shakeTime

Time remaining for the shaking animation before falling. When greater than 0, the doodad shakes horizontally using a sine wave pattern. Decrements each frame, and when it reaches 0, triggers falling and attempts to collapse doodads above. Also affects the Falling property.


public bool takeDamageOnFall = true

When true, the doodad will call Death() if it hits the ground with sufficient velocity (yI < -40). Checked in the Update() falling logic when the doodad lands on the ground. Allows doodads to be destroyed by falling from height.


public bool tintScorchedSprite

When true, fire damage progressively darkens the sprite to show scorching. Uses scorchDamage to control tint darkness.


public bool waitForDamageToFall

When true, prevents the doodad from falling even if falling is true, until it takes damage. Reset to false in both Damage() and DamageOptional() methods, and in Disturb(). Checked in Update() to gate the falling physics. Used for doodads that should remain suspended until damaged.


public bool willExplode = true

Determines whether this doodad creates an explosion when destroyed. When true in MakeEffectsDeath(), calls CreateExplosion() which creates explosion effects, burns nearby units, and damages units with explosion damage. When false, creates non-explosive death effects instead.


Position & Physics

Methods

protected virtual void Bounce()

Resets the doodad's falling state after landing. Sets vertical velocity to zero, marks as settled (no longer falling), and clears the falling flag. Can be overridden for custom bounce behavior.


public override void Disturb()

Disturbs the doodad, potentially causing it to fall. Calls the base class Disturb method first, then if fallOnDisturb is true, triggers any attached chain anchor to collapse, clears the waitForDamageToFall flag, and initiates falling without forcing disturbance of objects above. This override extends the base behavior to add falling mechanics for disturbed doodads.


protected virtual void GetGroundHeight()

Calculates the highest ground point beneath the doodad using raycasts. Casts rays downward at 16-unit intervals across the doodad's width, finds the highest hit point as ground height, damages terrain blocks if less than 50% have solid ground beneath (crushing weak supports), and initiates falling if no ground is detected. Uses the doodad's width in blocks to determine raycast positions.


protected virtual bool GroundBelowInadiquate(float hitRatio)

Determines if the ground support beneath the doodad is insufficient. Returns true if 50% or less of the doodad's width has solid ground support, indicating unstable foundation that should be crushed.

Parameters:

  • float hitRatio: Ratio of successful ground hits to total width in blocks (0.0 to 1.0)

Returns:

  • bool: True if ground support is inadequate (50% or less), false otherwise

protected virtual void HitUnits()

Checks for and damages units beneath the falling doodad. Only active during edit mode or when falling. Attempts to crush units with two different damage values (15 and -1) within a 6-unit high area below the doodad. Calls Bloody() on successful hits. Respects dontCrushOnceDestroyed flag to prevent dead doodads from crushing.


protected virtual void Land()

Handles all effects and mechanics when a falling doodad hits the ground. Creates sand particles if configured, fires plasma projectiles in multiple directions if shootPlasmaBoltsOnGroundImpact is set, triggers screen shake based on screenShakeAmountOnFall, plays impact sound effects, destroys the doodad if destroyDoodadOnFall is true, and calls Bounce to handle velocity changes. Plasma bolts are fired at 100, 200, and 300 units/second in both directions.


protected virtual void RunXMovement(float t)

Updates the doodad's horizontal position based on X velocity. Calculates movement distance from velocity and deltaTime, then adds it to current X position. Used for horizontal movement when falling or being pushed.

Parameters:

  • float t: Delta time for this frame

protected virtual void SetPosition(float xOffset)

Sets the doodad's transform position with an optional X offset. Updates the GameObject transform to the current X + offset and Y coordinates. Typically used to apply shake effects.

Parameters:

  • float xOffset: Horizontal offset to add to base position, usually for shake effects

public override void SetXY(float x, float y)

Sets the position of the doodad and marks it as needing a position update. Calls the base SetXY method to update the internal position, then sets xyDirty to true to ensure the visual transform is updated in the next Update cycle. This override ensures position changes are properly synchronized with the visual representation.

Parameters:

  • float x: The new X coordinate for the doodad
  • float y: The new Y coordinate for the doodad

Fields

public Vector3 bottomLeftOffset

Vector3 offset from the transform position to the bottom-left corner of the doodad. Used in GetGroundHeight() as the starting point for ground detection raycasts across the width of the doodad. Also used in CreateFlames() for flame effect positioning.


public bool canFall = true

Master flag controlling whether this doodad can fall at all. When false, prevents all falling behavior in Update() and StartFalling(). When true (default), allows normal falling physics. Also checked in Collapse() and Death() methods.


public bool falling

Indicates whether this doodad is currently falling. Set to true by StartFalling(), in Death(), and when shakeTime expires. Set to false in Bounce() when landing. The Falling property returns true if either this field is true or shakeTime > 0.


protected float groundHeight

The Y position of the ground below this doodad, calculated by GetGroundHeight() using raycasts. Updated each frame when falling to determine landing position. Used in Update() to check if the doodad has reached the ground (Y <= groundHeight + 8f).


private float previousXOffset = -1f

Cached horizontal shake offset from previous frame. Used to detect when position needs updating due to shake changes.


protected RaycastHit raycastHit

Primary RaycastHit used for ground detection in GetGroundHeight(). Stores the result of downward raycasts from each block width position to find the highest ground point. Also used in TryCollapseAbove() for upward raycasts to find objects to collapse.


protected RaycastHit raycastHitLeft

Currently unused RaycastHit field. Likely intended for additional ground detection on the left side of multi-block wide doodads, but not implemented in current code.


protected RaycastHit raycastHitRight

Currently unused RaycastHit field. Likely intended for additional ground detection on the right side of multi-block wide doodads, but not implemented in current code.


public Vector3 topLeftOffset

Vector3 offset from the transform position to the top-left corner of the doodad. Used in TryCollapseAbove() as the starting point for upward raycasts to detect and collapse doodads or blocks positioned above this one.


protected bool xyDirty

Flag indicating the position has changed and needs to be updated this frame. Set when physics or external changes occur.


Environmental Interaction

Methods

public override void Collapse()

Handles collapse mechanics for the doodad with different behaviors based on state. If the doodad can fall and isn't already falling, broadcasts StartFalling via RPC. Otherwise forces destruction by dealing crushing damage exceeding max health, creates leaf effects if configured, creates blood effects if configured, and marks as dead. Overrides base Doodad.Collapse to add falling mechanics.


protected virtual void OnCollisionEnter(Collision collisio)

Unity collision callback for when the doodad collides with other objects. Currently empty but virtual, allowing derived classes to implement custom collision responses.

Parameters:

  • Collision collisio: The collision data from Unity's physics system

public void StartFalling(bool forceDisturbAbove)

Initiates the falling sequence for this doodad. Sets the falling flag if canFall is true, and optionally triggers collapse of objects above. If shakeBeforeFalling is enabled and forceDisturbAbove is false, delays the collapse trigger until after shaking completes.

Parameters:

  • bool forceDisturbAbove: If true, immediately triggers collapse of objects above regardless of shake settings

public override bool SubMergesUnit()

Determines if units can partially merge with this doodad for visual depth. Returns true (allowing merging) only when the doodad is pristine - neither dead nor damaged. Used for visual layering of units behind environmental objects.

Returns:

  • bool: True if units can merge with this doodad, false if damaged or dead

protected virtual void TryCollapseAbove()

Attempts to trigger falling or collapse of doodads and blocks directly above this one. Only executes if CollapseDoodadsAboveWhenDestroyed is true. Casts rays upward at 16-unit intervals across the doodad's width, triggers Collapse on any Doodad within 9 units above, calls Disturb on FallingBlocks to start their fall sequence, and disturbs self when affecting FallingBlocks. Used to create chain reaction collapses.


Fields

public bool CollapseDoodadsAboveWhenDestroyed

When true, triggers collapse of doodads directly above this one when destroyed or shaking. Creates chain reaction collapses.


public bool collapseOnLanding = true

When true, automatically triggers Collapse() when the doodad lands after falling. Default is true.


public bool crushUnitsAndTerrain

Enables crushing damage to units below when falling. When true in HitUnits(), performs two damage checks using Map.HitUnits() with DamageType.Crush. Only applies damage if the doodad is above ground level or (if dontCrushOnceDestroyed is true) not yet dead.


public bool destroyDoodadOnFall

When true, immediately destroys the GameObject when the doodad lands after falling. Checked in Land() method and calls UnityEngine.Object.Destroy(gameObject). Used for objects that should disappear completely upon impact.


public bool dontCrushOnceDestroyed

Modifies crushing behavior when crushUnitsAndTerrain is true. When this is true, crushing damage only occurs if the doodad is not dead (!isDead). When false, crushing occurs whenever the doodad is above ground height. Checked in HitUnits() method.


public bool fallOnDisturb

When true, causes the doodad to start falling when Disturb() is called. Collapses any attached chain anchor, sets waitForDamageToFall to false, and calls StartFalling(false). Used for objects triggered by nearby disturbances rather than direct damage.


public Projectile plasmaProjectile

The projectile prefab used when shootPlasmaBoltsOnGroundImpact is true. Spawned 6 times in Land() method with different velocities (±100, ±200, ±300 X velocity) from the left and right edges of the doodad.


public bool shootPlasmaBoltsOnGroundImpact

When true, spawns 6 plasma projectiles in different directions upon landing. Set to false after firing in Land(). Uses the plasmaProjectile field as the projectile template. Creates spark particle effects if createSparksOnDeath is also true.