Invincibility frame

From Terraria Wiki
(Redirected from Invincibility frames)
Jump to navigation Jump to search

An invincibility frame (also known as immune frame, immunity frame, or invulnerability frame, sometimes abbreviated to iframe or i-frame) is a brief period of time during which an entity cannot take any damage. It is usually granted immediately after taking damage.

The general purpose of invincibility frames is to prevent an entity from taking too much damage from continuous or rapidly repeated damage sources. For instance, if there are no invincibility frames, a player submerged in lava would take damage from it every tick[1], i.e. 60 times per second.

Players in particular are also granted invincibility frames under a few other conditions, not just taking damage.

Player invincibility

The player gets an invincibility frame after taking damage from any source. The length of the invincibility frame varies depending on the circumstances; certain items will also provide invincibility frames when their effects are triggered. See below for details.

Invincibility groups

On the Desktop version Desktop version, Console version Console version, and Mobile version Mobile version, some groups of damage sources grant separate "types" of invincibility frames. These different types of invincibility frames will not interfere with each other. The vast majority of damage sources are in the same group ("Group 4" below), but there are three other groups:

Group 1
Damage inflicted by darkness in a Constant world[2], and damage inflicted by these tiles:[3]
Group 2
All damage inflicted by these bosses:[4]
Group 3
Damage inflicted by lavalava.[5]
Group 4
All other damage sources.

For example, if the player takes damage from a Spike ("Group 1" above), they will not take any damage from e.g. touching a Rolling Cactus (also "Group 1") for the duration of the invincibility frame, but they will still take damage from e.g. an enemy ("Group 4") during this time.

On the Old-gen console version Old-gen console version and Nintendo 3DSNintendo 3DS version version, there are no different groups of invincibility. All damage sources grant the same "type" of invincibility frame.

Invincibility frame length

Taking damage usually grants the player an invincibility frame of 0.67 seconds by default. This duration is halved if the amount of damage taken is 1, and is even lower in PvP. The Cross Necklace and its upgrades increase the length of the invincibility frame[a]. Various other effects also grant an invincibility frame, such as respawning, dodging, parrying, or dealing damage with a mount. See the following table for details.

Source Default[b] Cross Necklace[c]
Default invincibility frames
when taking damage[6]
0.67 seconds 1.33 seconds
If the damage taken is 1[6] 0.33 seconds 0.67 seconds
PvP damage[d] 0.13 seconds n/a
Respawning after dying in PvP[7] 5 seconds n/a
Respawning after dying
outside of PvP[7]
3 seconds n/a
When entering a world, or being
teleported back to spawn point
(e.g. via Magic Mirror)[7]
1 second n/a
Holy Protection Holy Protection(Desktop, Console and Mobile versions)[8] 1.33 seconds[e] 2 seconds[e]
Shadow Dodge Shadow Dodge(Old-gen console and 3DS versions)
Black Belt Black Belt(and its upgrades)[9]
Brain of Confusion Brain of Confusion(Dodge effect)[10]
Brand of the Inferno Brand of the Inferno(Desktop, Console and Mobile versions)(shield parry)[11] 0.5 seconds 1 second
Sergeant United Shield Sergeant United Shield(Desktop, Console and Mobile versions)(shield parry)
Strange Brew Strange Brew(Desktop, Console and Mobile versions)[12] Provide invincibility frames at
different chances when used:[e]

11%: 4 seconds
20%: 2 seconds
30%: 1 second
39%: None

n/a
Companion Cube Companion Cube(Desktop, Console and Mobile versions)(stab)[13] None n/a
Slime Mount Slime Mount(Desktop, Console, Old-gen console and Mobile versions)(on hit)[14] 0.1 seconds n/a
Winged Slime Mount Winged Slime Mount(Desktop, Console and Mobile versions)(on hit)
Unicorn Mount Unicorn Mount(Desktop, Console and Mobile versions)(on hit)[15]
Painted Horse Mount Painted Horse Mount(Desktop, Console and Mobile versions)(on hit)
Majestic Horse Mount Majestic Horse Mount(Desktop, Console and Mobile versions)(on hit)
Dark Horse Mount Dark Horse Mount(Desktop, Console and Mobile versions)(on hit)
Goat Mount Goat Mount(Desktop, Console and Mobile versions)(on hit)
Pirate Ship Mount Pirate Ship Mount(Desktop, Console and Mobile versions)(on hit)
Tree Mount Tree Mount(Desktop, Console and Mobile versions)(on hit)
Basilisk Mount Basilisk Mount(Desktop, Console and Mobile versions)(on hit)
Lawn Mower Lawn Mower(Desktop, Console and Mobile versions)[16]
Golf Cart Golf Cart(Desktop, Console and Mobile versions)(on hit) 0.2 seconds n/a
Shield of Cthulhu Shield of Cthulhu(Desktop, Console and Mobile versions)(dash hit)[17] 0.07 seconds n/a
Solar Flare armor Solar Flare armor(Desktop, Console and Mobile versions)(dash hit)

Entity invincibility

"Piercing" redirects here. For the removed, Mobile version Mobile-exclusive modifier, see Modifiers § History.
See also: Introduction to enemy invincibility by Leinfors (under "Spoiler: 1.4.4 Balance Changes", then "Spoiler: Glossary")
For a complete list of "piercing" projectiles, see List of projectiles that apply invincibility frame.

Non-player entities (enemies, critters, and friendly NPCs) will receive an invincibility frame from player's "piercing" or "continuous" attacks, i.e. attacks from any damage source that can strike an entity and then remain able to cause damage afterwards.[18] This includes player-inflicted damage sources like Meteor Shots, Unholy Arrows, the Vilethorn, or the Rainbow Gun, but also hazards like projectile-firing traps. The invincibility frame for entities usually lasts 0.17 seconds.

Internally, whether a projectile is considered "piercing" is determined by its penetrate. This stat determines how many targets a single projectile can hit.[19] If the penetrate value is more than 1, the projectile is considered "piercing". After a projectile deals damage to a target, its penetrate stat is reduced by 1, and the projectile dissipates when penetrate reaches 0. Projectiles with a penetrate value of 1 is considered "non-piercing" — the projectile will dissipate upon hitting a target, does not grant hit entity any invincibility frame, and is not affected by invincibility frames.

  • A "piercing" projectile will become "non-piercing" when its penetrate reaches 1 (i.e. after hitting enough targets).

There are three different ways in which damage sources grant entities invincibility:

  • Global invincibility: Invincible to all piercing damage and melee hits from one player.
  • Static invincibility: Invincible to damage from other projectiles of the same type from one player.
  • Local invincibility: Invincibile to damage from that specific projectile.

Global invincibility

If a player's projectile applies global invincibility, damaged entities will be temporarily invulnerable to all sources of piercing damage and all melee hits from melee weapons[20] from the same player, including other types of attacks, for the duration of the invincibility frame. It lasts 0.17 seconds by default, but is different for certain projectiles to allow faster or slower hitting. In multiplayer, this type of invincibility is checked separately for each player, so one player applying global invincibility to an entity does not prevent other player's piercing damage from hurting it.

This was the original implementation of Terraria's invincibility frame system for entities, so a large number of projectiles (especially older ones) use global invincibility. This type of invincibility basically "blocks" the player from doing damage with different types of piercing damage sources. Many projectiles that grant global invincibility were balanced around this limitation, doing more damage than they might otherwise if they were not.

On the Old-gen console version Old-gen console version and Nintendo 3DSNintendo 3DS version version, global invincibility applies to all piercing projectiles. This can sharply limit the effects of other piercing weapons used against the same target, as well as weapons that fire multiple piercing projectiles such as the Poison Staff. Most minions are considered to have piercing attacks, which can also hinder the efficiency of piercing weapons used alongside them. This problem is remarkably present with the Spider Staff.

Static invincibility

If a projectile applies static invincibility, damaged entities will only be invulnerable to damage from projectiles of that specific projectile type (i.e. projectiles with the same ID). All projectiles of that type from the same player will not able to deal damage to the entity for the duration of the invincibility frame. Projectiles of that type from other players are unaffected.

Using this type of invincibility, though repeated hits from the same type of piercing projectile during the invincibility frame will not be able to land, hits from any other type of piercing projectile will be able to deal damage. Most projectiles that grant static invincibility are balanced around this fact.

For example, after Wasp Gun's Wasp (projectile ID 189) damages an entity, the entity will become temporarily invincible from all Wasps. For the duration of invincibility frame, Wasps will pass through it without dealing damage. However, the entity will still take damage from any other type of projectile during Wasps' invincibility frame, such as a Nimbus Rod raindrop (projectile ID 239, different from Wasp's ID 189) or a Raven minion (projectile ID 317).

Local invincibility

If a projectile applies local invincibility, damaged entities will only be invulnerable to the projectile itself (i.e. the exact specific projectile instance that inflicted the damage) for the duration of the invincibility frame. All other piercing projectiles, even projectiles of the same type, can still deal damage during the invincibility frame.

Therefore, firing large quantities of projectiles that grant local invincibility is not as inefficient as with static invincibility. As this type of invincibility was not widely used for a majority of Terraria's history, almost all piercing weapons were not balanced around it.

For example, Deadly Sphere minions (which grant local invincibility) all operate on their own independent invincibility timers and will not conflict with each other at all. If one Deadly Sphere damages an entity, another Deadly Sphere can still inflict damage during the invincibility frame granted by the first minion. At higher summon counts, Deadly Spheres are able to inflict significantly more damage than if they granted global or static invincibility.

Technical info

Each type of invincibility frame is implemented differently.

Global invincibility

Each entity keeps track of an immune time array which has 256 elements.[21] Among these elements, the first 255 of them each corresponds to a player; the last, 256th one does not correspond to any player (it can be considered as the default damage source). Each element has a value of 0 by default. If it is greater than 0, it will be reduced by 1 each tick, and the damage source corresponding to it cannot deal damage to the entity.

When global invincibility is applied to an entity, the length of the invincibility frame is added to the element corresponding to the damage source in the list. In most cases, the damage source is the player who shot the projectile. However, if the damage is not related with any player, or it is unable to find a player as the damage source, the damage is considered coming from the default damage source and the length of the invincibility frame will be added to the 256th element.

In singleplayer, the damage source of all friendly projectiles (i.e. all projectiles that are able to deal damage to enemies, this includes projectiles from weapons, NPCs, traps, etc.) is considered as the player.

In these cases, damage source is considered as the default damage source:

  • Damage dealt to non-player entities from "non-player sources". See below for details.
  • In multiplayer:
    • Projectiles not directly created by the player, usually tiles that can create projectiles like Boulders, TNT Barrels(Desktop, Console and Mobile versions), etc.Verify[22]
    • Projectiles created from traps like Dart Trap via triggers, but the trigger is not directly activated by player.[23]

Static Invincibility

The game keeps track of a two-dimensional array perIDStaticNPCImmunity with 1022 rows and 200 columns (perIDStaticNPCImmunity[1022][200]).[24] Each row represents for a type of projectile, and each column represents for an NPC slot.

When a projectile that applies static invincibility damages an entity, the value of the element perIDStaticNPCImmunity[the projectile's ID][NPC slot index] is set to Current game time[f] + length of invincibility frame. "Length of invincibility frame" equals to the projectile's idStaticNPCHitCooldown stat.[25] After the projectile damages an entity, it will also set the length of the entity's global invincibility time to the respective damage source to zero.

When a projectile that applies static invincibility is going to damage an entity, the game will check whether the value of the element perIDStaticNPCImmunity[the projectile's ID][NPC slot index] is no more than current game time. If it is greater than current game time, the projectile will not be able to deal damage to the entity.

For example, a player attacks an entity with the NPC slot index of 0 with the Frostbrand's Frost Bolt projectile (ID 119, applies 10 ticks of static invincibility frame) will set the value of the element perIDStaticNPCImmunity[119][0] to Current game time + 10. As a result, in the following 10 ticks, any Frost Bolt projectiles from the same player will not be able to deal damage to this entity.

Local Invincibility

Each projectile keeps track of an immune time array which has 200 elements[26], with each element corresponding to an NPC slot. Each element has a value of 0 by default. When a projectile that applies local invincibility damages an entity, the value of the element corresponding to the NPC slot occupied by the entity will be set to the length of invincibility frame. "Length of invincibility frame" equals to the projectile's localNPCHitCooldown stat.[27] The projectile cannot deal damage to the entity occupying the NPC slot when the value of the related element is not 0. Also, if the projectile's localNPCHitCooldown is not -2, after it damages an entity, it will also set the length of the entity's global invincibility time to the respective damage source to zero.

The reducing of the value is affected by the projectile's extraUpdates stat since it is based on projectile update. Projectile update happens once per tick by default, and an extraUpdates value of n means the projectile is updated an extra n times per tick. The value will be reduced by 1 per update if it is greater than 0.

Furthermore, localNPCHitCooldown has two special values: -1 and -2.

  • If localNPCHitCooldown is -1, it means that the entity damaged by the projectile becomes permanently immune to that specific projectile; the entity can never be damaged by that specific projectile again. In other words, a single entity can only be hit by a projectile once.
  • If localNPCHitCooldown is -2, the mechanics about local invincibility are simply ignored. None of the values in the local invincibility immune time array is changed; instead, the projectile will follow common behavior of piercing projectiles, inflicting 10 ticks of global invincibility frames when damaging entities if the projectile can pierce.

If localNPCHitCooldown is not a negative value, the actual length of local invincibility of a projectile (in ticks) can be calculated by the following formula:

[math]\displaystyle{ \text{Invinciblity frame}=\left\lfloor\frac{\textit{localNPCHitCooldown}}{\textit{extraUpdates}+1}\right\rfloor + \textit{localNPCHitCooldown}\mod(\textit{extraUpdates}+1) }[/math]

For example, attacking an entity with the NPC slot index of 0 with Star Wrath's projectile (ID 503, applies 30 ticks of local invincibility frame, has an extraUpdates value of 1) sets the value of the first element in the list to 30. The value will be reduced by 2 each tick, making the actual length of invincibility frame 15 ticks.

Entity invincibility from non-player sources

Non-player entities will also get invincibility frames after taking damage from lava, or after taking contact damage from other non-player entities. They cannot be hurt by lava and other non-player entities again for the duration of the invincibility frame. These damage are not considered from any player, so they will not interfere with any type of invincibility frames from player attacks.[28]

When taking damage from lava, all entities will receive 0.5 seconds of invincibility frame.

When taking contact damage, the Eternia Crystal(Desktop, Console and Mobile versions) will receive 0.33 seconds of invincibility frame, while all other entities will receive 0.5 seconds of invincibility frame.

Only a few methods can make non-player entities receive contact damage from each other, including:

  • Critters and town NPCs taking contact damage from enemies.
  • (Desktop, Console and Mobile versions) Eternia Crystal taking damage from enemies.
  • (Desktop, Console and Mobile versions) Bees attacking enemies.
  • (Desktop, Console and Mobile versions) The Queen Bee dealing and receiving damage to other enemies when Bees exist.

History

  • Desktop 1.4.1.2: Damage from lava to players now has its own group of invincibility, separate from all other damage sources.
  • Desktop 1.3.0.5: Damaging tiles (Thorny bushes, Spikes, and Wooden Spikes) against players now have their own group of invincibility, separate from all other damage sources.

References

  1. A tick is a time unit countable by the software. Most of Terraria's updating logic happens every tick. A tick has the length of 1/60th of a second, hence there are 60 ticks in a second and 3600 ticks in a minute.
  2. Information taken from the Desktop version Desktop 1.4.4.9 source code, method Update() in Terraria.GameContent.DontStarveDarknessDamageDealer.cs.
  3. Information taken from the Desktop version Desktop 1.4.4.9 source code, method ApplyTouchDamage() in Terraria.Player.cs.
  4. Information taken from the Desktop version Desktop 1.4.4.9 source code, method Update_NPCCollision() in Terraria.Player.cs.
  5. Information taken from the Desktop version Desktop 1.4.4.9 source code, method Update() in Terraria.Player.cs.
  6. 6.0 6.1 Information taken from the Desktop version Desktop 1.4.4.9 source code, method Hurt() in Terraria.Player.cs.
  7. 7.0 7.1 7.2 Information taken from the Desktop version Desktop 1.4.4.9 source code, method Spawn() in Terraria.Player.cs.
  8. Information taken from the Desktop version Desktop 1.4.4.9 source code, method ShadowDodge() in Terraria.Player.cs.
  9. Information taken from the Desktop version Desktop 1.4.4.9 source code, method NinjaDodge() in Terraria.Player.cs.
  10. Information taken from the Desktop version Desktop 1.4.4.9 source code, method BrainOfConfusionDodge() in Terraria.Player.cs.
  11. Information taken from the Desktop version Desktop 1.4.4.9 source code, method Update_NPCCollision() in Terraria.Player.cs.
  12. Information taken from the Desktop version Desktop 1.4.4.9 source code, method ApplyLifeAndOrMana() in Terraria.Player.cs.
  13. Information taken from the Desktop version Desktop 1.4.4.9 source code, method AI_067_FreakingPirates() in Terraria.Projectile.cs.
  14. Information taken from the Desktop version Desktop 1.4.4.9 source code, method JumpMovement() in Terraria.Player.cs.
  15. Information taken from the Desktop version Desktop 1.4.4.9 source code, method HorizontalMovement() in Terraria.Player.cs.
  16. Information taken from the Desktop version Desktop 1.4.4.9 source code, method MowTheLawn() in Terraria.Player.cs.
  17. Information taken from the Desktop version Desktop 1.4.4.9 source code, method DashMovement() in Terraria.Player.cs.
  18. Information taken from the Desktop version Desktop 1.4.4.9 source code, method Damage() in Terraria.Projectile.cs.
  19. Information taken from the Desktop version Desktop 1.4.4.9 source code, field penetrate in Terraria.Projectile.cs.
  20. Information taken from the Desktop version Desktop 1.4.4.9 source code, method ItemCheck_MeleeHitNPCs() in Terraria.Player.cs. Note that melee hits are merely affected by global invincibility, they do not apply global invincibility frames when dealing damage.
  21. Information taken from the Desktop version Desktop 1.4.4.9 source code, field immune in Terraria.NPC.cs.
  22. Information taken from the Desktop version Desktop 1.4.4.9 source code, field myPlayer in Terraria.Main.cs and method InitializeServer() in Terraria.Netplay.cs.
  23. Information taken from the Desktop version Desktop 1.4.4.9 source code, field CurrentUser in Terraria.Wiring.cs and method SetCurrentUser() in Terraria.Wiring.cs.
  24. Information taken from the Desktop version Desktop 1.3.5.3 source code, method IsNPCIndexImmuneToProjectileType() in Terraria.Projectile.cs and field perIDStaticNPCImmunity in Terraria.Projectile.cs. There may be inaccuracies, as the current Desktop version Desktop version is 1.4.4.9.
  25. Information taken from the Desktop version Desktop 1.4.4.9 source code, field idStaticNPCHitCooldown in Terraria.Projectile.cs.
  26. Information taken from the Desktop version Desktop 1.4.4.9 source code, field localNPCImmunity in Terraria.Projectile.cs.
  27. Information taken from the Desktop version Desktop 1.4.4.9 source code, field localNPCHitCooldown in Terraria.Projectile.cs.
  28. Information taken from the Desktop version Desktop 1.4.4.9 source code, methods BeHurtByOtherNPC() in Terraria.NPC.cs and Collision_LavaCollision() in Terraria.NPC.cs.
  1. The Cross Necklace and its upgrades do not stack with each other.
  2. Invincibility frames provided by default.
  3. Invincibility frames provided if the Cross Necklace or its upgrades is equipped. "n/a" means not affected by Cross Necklace.
  4. Includes both damage from another player and self-induced damage, e.g. explosives and (Old-gen console and 3DS versions) Exploding Bullets.
  5. 5.0 5.1 5.2 Provide all types of invincibility frames. Information taken from the Desktop version Desktop 1.4.4.9 source code, method SetImmuneTimeForAllTypes() in Terraria.Player.cs.
  6. This game time is the time elapsed from starting game session (in ticks). It is not related with the in-game time tracked by watches.