Sin Costan
Eye of Cthulhu
There is a tModLoader version of this tutorial, just post in there if you have tModLoader related questions. You can find it in my sigature under "My tModLoader Stuff".How do I make a modded projectile pass through tiles, but becomes solid when it reaches the cursor? I'm using tModLoader, btw.![]()
To answer your question now, if you mean by no tile collision and then tile collision, then just use Shoot() hook, spawn a new Projectile with Projectile.NewProjectile and add the mouse positions for the last two parameters of that function. Note, things will act funky if you are using a vanilla AI style if you store the mouse positions in the projectile's AI slots. Afterwards, we go onto your projectile, in which for your AI, we want the defaults to include tile collision, meaning tileCollide = false. After wards you can just check the relative distance between the projectile and the point and then turn on tile collision.
Here is essentially what you want... But try to do what I said above before looking at the code so you can learn how to do it.
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
//Get mouse position in the screen
Vector2 relativePoint = Main.player[projectile.owner].RotatedRelativePoint(Main.player[projectile.owner].MountedCenter, true);
float mouseX = (float)Main.mouseX + Main.screenPosition.X - relativePoint.X;
float mouseY = (float)Main.mouseY + Main.screenPosition.Y - relativePoint.Y;
//Spawn a new projectile with the same stuff as the params except adding in the mouse positions in the AI of the projectile
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, 0, knockBack, player.whoAmI, mouseX, mouseY);
//Makes sure it doesn't spawn the original projectile
return false;
}
public override void AI()
{
//Get the distance
float dToX = projectile.ai[0] - projectile.Center.X;
float dToY = projectile.ai[1] - projectile.Center.X;
float distance = (float)System.Math.Sqrt((double)(dToX * dToX + dToY * dToY));
//If the distance between the projectile and the point is less than 100 pixels, then it will collide with tiles
if(distance < 100f)
{
projectile.tileCollide = true;
}
}