Projectile Class
Comments56this wiki
| The information in this article is for Terraria v1.0.6.1. |
|
The projectile class is where the awesome mods will stand themselves apart from the other ones. This class is responsible for handling all the projectiles and their behavior in the game. You can even create new projectiles that mimic existing behavior, or if you are skilled enough, decompile the game and give them all new AI. | ||||
|
|
Properties
Edit
| Name | Type | Description |
|---|---|---|
| active | bool | If true, the projectile is alive and receiving updates |
| ai | float[] | An array of two float variables you can use to sync projectile information between different clients on a server. |
| aiStyle | int | The visual and behavior effect of the projectile |
| alpha | int | The transparency of the projectile. Should be a number from 0 to 255. Default is 255. |
| damage | int | The damage done by the projectile |
| direction | int | |
| friendly | bool | If true, the projectile will not harm players or friendly NPCs |
| height | int | The height of the projectile in pixels.
|
| hide | bool | If true, the projectile is not visible. These projectiles can still harm players and npcs |
| hostile | bool | If true, the projectile will not harm hostile NPCs |
| identity | int | |
| ignoreWater | bool | If true, the projectile may pass through water |
| knockBack | float | The power of knockback |
| lavaWet | bool | |
| light | float |
The power of the light emitted. |
| magic | bool | Whether the projectile deals magic damage or not. Melee supersedes ranged, which supersedes magic. |
| maxUpdates | int | |
| melee | bool | Whether the projectile deals melee damage or not. Melee supersedes ranged, which supersedes magic. |
| miscText | string | |
| name | string | |
| netUpdate | bool | |
| numUpdates | int | |
| owner | int | The whoAmI value of the owner. This is used for Light Orbs so they can follow the owner |
| ownerHitCheck | bool | |
| penetrate | int | |
| playerImmune | int[] | |
| position | Vector2 | |
| ranged | bool | Whether the projectile deals melee damage or not. Melee supersedes ranged, which supersedes magic. |
| restrikeDelay | int | |
| rotation | float | A value of 1 is equal to 60 degrees (so a value of 6 is 360 degrees) |
| scale | float | A multiplier that affects the size of the sprite |
| soundDelay | int | |
| spriteDirection | int | The direction the sprite will be drawn facing. -1 = left, 1 = right. |
| tileCollide | bool | If true, the projectile will die when hitting a tile. |
| timeLeft | int | A timer that affects how long the projectile exists for. |
| type | int | |
| velocity | Vector2 | The speed of the projectile along the X and Y axes. |
| wet | bool | |
| wetCount | byte | |
| whoAmI | int | Index of Main.projectile[] for this projectile instance |
| width | int | The width of the projectile in pixels.
|
Static Properties
Edit
| Name | Type | Description |
|---|---|---|
| None | N/A | N/A |
Methods
Edit
| Method Name | Description |
|---|---|
| AI() |
public void AI()
{
}
Here you can specify AI functionality for the projectile you're coding.
|
| Damage() |
public void Damage()
{
}
???
|
| GetAlpha() |
public Color GetAlpha(Color newColor)
{
}
Gets the projectile's alpha blending value
|
|
PreKill() |
public void PreKill()
{
}
Called immediately before Kill(), use this or PostKill() if you want something to happen when your projectile dies.
|
|
Kill() |
public void Kill()
{
}
Called when the projectile meets destruction criteria (hits a tile, runs out of time, etc.). Don't play with this unless you know what you're doing.
|
|
PostKill() |
public void PostKill()
{
}
Called immediately after Kill(), use this or PreKill() if you want something to happen when your projectile dies.
|
| SetDefaults() |
public void SetDefaults(int Type)
{
}
???
|
| StatusNPC |
public void DamageNPC(NPC npc, ref int damage, ref float knockback)
{
}
Invoked when the projectile hits an NPC
|
| StatusPlayer() |
public void StatusPlayer(int i)
{
}
Invoked when the projectile hits a player
|
| StatusPvP |
public void StatusPvP(int i)
{
}
Invoked when the projectile hits a player in pvp combat
|
| Update() |
public void Update(int i)
{
}
???
|
Static Methods
Edit
| Method Name | Description |
|---|---|
| NewProjectile() |
public static int NewProjectile(
float X,
float Y,
float SpeedX,
float SpeedY,
int Type,
int Damage,
float KnockBack,
[int Owner = 255]
)
Spawns a new projectile with the given parameters
|
Notes
Edit
In the AI method is where you can specify dust particles for things like spears and other projectiles as that's where they are handled in the source code. It's not too simple however... you will need to have the source code to look at to replicate the proper function of the kind of projectile you're working with.
| Classes in Terraria |
|---|
|
Chest | Cloud | Collision | Dust | Gore | Item | Lighting | Liquid | Main | NPC | Player | Projectile | Recipe | Sign | Star | WorldGen |

Added by