Guido65
Terrarian
What do you mean by spawning a specific projectile on a target? If you mean changing what the projectile is firing, you just modify 5th parameter in Projectile.NewProjectile. Here's a layout of the parameters of the Projectile.NewProjectile.
Code:Projectile.NewProjectile( int positionX, int positionY, float velocityX, float velocityY, int type, int damage, float knockback, int ownerId, float ai1, float ai2 )
If this is not the case, could you give me an example of what you mean by your question?
I got this figured out now but when I throw the projectile(it's a boomerang) it just immediately despawns.
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace GuidosMod.projectiles
{
public class NightBoomerang : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "NightBoomerang";
projectile.width = 35;
projectile.height = 42;
projectile.timeLeft = 2400;
projectile.penetrate = -1;
projectile.friendly = true;
projectile.hostile = false;
projectile.tileCollide = true;
projectile.ignoreWater = true;
projectile.melee = true;
projectile.aiStyle = 3;
}
public override void AI()
{
for(int i = 0; i < 200; i++)
{
//Enemy NPC variable being set
NPC target = Main.npc[i];
//Getting the shooting trajectory
float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
float shootToY = target.position.Y - projectile.Center.Y;
float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
//If the distance between the projectile and the live target is active
if(distance < 480f && !target.friendly && target.active)
{
if(projectile.ai[0] > 4f) //Assuming you are already incrementing this in AI outside of for loop
{
//Dividing the factor of 3f which is the desired velocity by distance
distance = 3f / distance;
//Multiplying the shoot trajectory with distance times a multiplier if you so choose to
shootToX *= distance * 5;
shootToY *= distance * 5;
//Shoot projectile and set ai back to 0
Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, mod.ProjectileType("UnholyStar")
, 30, 0, Main.myPlayer, 0f, 0f); //Spawning a projectile
Main.PlaySound(33, (int)projectile.position.X, (int)projectile.position.Y, 88);
projectile.ai[0] = 0f;
}
}
}
projectile.ai[0] += 1f;
}
}
}