tModLoader Projectiles and blocks

silentstorm_

Steampunker
I'm making a mod, and I'd like to make some projectiles go "behind" chosen blocks like glass (and can be seen through it) and collide with rest, but I have no idea if it's even possible.
Also, how do I make a projectile that appears almost instantaneously when a (chosen) block it's attached to another one (from any side, like a torch but even on bottom), goes straight for, like, twenty blocks, then ends with a special sprite and lingers until one of the blocks is destroyed?
 
Last edited:
There is no such thing as 'impossible' when it comes to coding, but these ideas are about as close as you can get, and definitely beyond what tModLoader is designed to handle, so you'd have to go standalone to begin with.

You'd need an extremely intricate understanding of how Terraria handles projectiles and collision to even attempt something like this. Unless these mechanics are fundamental to the theme or the workings of your mod, my advice to you is "don't bother".
 
So maybe just collide with one and not with rest?
Well, that would involve checking the tile it would collide with, probably checking the projectile's tile position, check a radius and enable tile collide or not, this hook might help you though.

Code:
public override bool OnTileCollide(Vector2 velocityChange)

Returning true destroys projectile while false makes it not. Vector2 velocityChange contains the velocity the projectile was before it collides with a tile.
 
And what about the second idea: placing a special tile makes a projectile (I know how to do this) which stays like the rainbow gun's one but until the block is destroyed?
Maybe just make the projectile linger a tick and make a new one every tick
Nope, this would lag the game too much.
Can the block target the projectile?
Maybe the projectile has an Update hook and knows its "starting point" (The point where it first appeared)
 
And what about the second idea: placing a special tile makes a projectile (I know how to do this) which stays like the rainbow gun's one but until the block is destroyed?
Maybe just make the projectile linger a tick and make a new one every tick
Nope, this would lag the game too much.
Can the block target the projectile?
Maybe the projectile has an Update hook and knows its "starting point" (The point where it first appeared)
You can just add to the projectile AI to check for the specific tile on a specific coordinate of a tile using the base ai[0] and ai[1] to store the tile coordinates. Then you can have the projectile check if that tile in that coordinate is still the same type, and if not, kill the projectile.
 
Back
Top Bottom