• For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Begin your search for Journey's End information here and here. Please report bugs and issues for Journey's End here.
  • For issues you find with the Mobile 1.3 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.

Hello there I'm relative new in Terraria Modding and I'cant find out how homing AI's working but here is my Version very bad or ?

Jiriki

Terrarian
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;
}
}
}
}
}
}
 

Greybrynn

The Destroyer
PLEAS HELP !!!
I can’t help you, but here is a tip for the future, getting help takes time, getting responses takes time, and please do not post more than once, bumping isn’t encouraged here, sorry if that sounded rude, but yeah it takes time bud your not always gonna get help immeadietly
Edit: I’m very very sorry if that sounded rude, I’m not trying to be rude, just trying to help you understand that things take time
 
Top Bottom