Hello there I'm relative new in Terraria Modding and I'cant find out how homing AI's work but here is my Version very bad or ?
Pleas Help! I searched everingthing and find nothing realy helpfull
Sorry for my bad english ; )
I'm desperate so Pleas Help wenn you see this
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Test.Projectiles
{
public class NiceBullet : ModProjectile
{
public override void SetStaticDefaults() {
DisplayName.SetDefault("Lingering Bullet");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
}
public override void SetDefaults() {
projectile.width = 8;
projectile.height = 8;
projectile.aiStyle = 1;
projectile.friendly = true;
projectile.hostile = false;
projectile.ranged = true;
projectile.penetrate = 5;
projectile.timeLeft = 600;
projectile.alpha = 255;
projectile.light = 0.5f;
projectile.ignoreWater = true;
projectile.tileCollide = true;
projectile.extraUpdates = 1;
}
public override void AI()
{
for (int i = 0; i < 200; i++)
{
NiceBullet target = Main.npc;
if (target.hostile)
{
//Get the shoot trajectory from the projectile and target
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 live targeted npc and the projectile is less than 480 pixels
if (distance < 480f && !target.friendly && target.active)
{
//Divide the factor, 3f, which is the desired velocity
distance = 3f / distance;
//Multiply the distance by a multiplier if you wish the projectile to have go faster
shootToX *= distance * 5;
shootToY *= distance * 5;
//Set the velocities to the shoot values
projectile.velocity.X = shootToX;
projectile.velocity.Y = shootToY;
}
}
}
}
}
}
Pleas Help! I searched everingthing and find nothing realy helpfull
Sorry for my bad english ; )
I'm desperate so Pleas Help wenn you see this
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Test.Projectiles
{
public class NiceBullet : ModProjectile
{
public override void SetStaticDefaults() {
DisplayName.SetDefault("Lingering Bullet");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
}
public override void SetDefaults() {
projectile.width = 8;
projectile.height = 8;
projectile.aiStyle = 1;
projectile.friendly = true;
projectile.hostile = false;
projectile.ranged = true;
projectile.penetrate = 5;
projectile.timeLeft = 600;
projectile.alpha = 255;
projectile.light = 0.5f;
projectile.ignoreWater = true;
projectile.tileCollide = true;
projectile.extraUpdates = 1;
}
public override void AI()
{
for (int i = 0; i < 200; i++)
{
NiceBullet target = Main.npc;
if (target.hostile)
{
//Get the shoot trajectory from the projectile and target
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 live targeted npc and the projectile is less than 480 pixels
if (distance < 480f && !target.friendly && target.active)
{
//Divide the factor, 3f, which is the desired velocity
distance = 3f / distance;
//Multiply the distance by a multiplier if you wish the projectile to have go faster
shootToX *= distance * 5;
shootToY *= distance * 5;
//Set the velocities to the shoot values
projectile.velocity.X = shootToX;
projectile.velocity.Y = shootToY;
}
}
}
}
}
}