FireBullets, Direction to Target?

In the following code:


local bullet = {}
		bullet.Num = /*data.bullets or */ 1
		bullet.Src = eye
		bullet.Dir = self:GetForward()
		bullet.Spread = Vector( 1 , 1, 0)
		bullet.Tracer = 1
		bullet.TracerName	= /* data.type or */ "Tracer"
		bullet.Force = 50
		bullet.Damage = /*data.damage */ 3
		bullet.AmmoType = "Pistol"
		bullet.Attacker = self

	self:FireBullets(bullet)

I have a nextbot that’s supposed to shoot a gun at enemies. It does that just fine, but with the bullet direction being “self:GetForward()”, it constantly misses.

I have an Aim function that causes my bot to aim its weapon at the enemy, but even so, it still misses, as the bot’s “forward” is not always the same as the enemy position in relation to the bot.
I can fix the problem by calling “self:loco:FaceTowards(self.Enemy)” along with my aim function, but that causes the bot’s model to twitch a lot, and i don’t want it to.

so, quickly, is there a way to get a relative vector to the bot’s enemy?


ang = ( theirpos - mypos ):GetNormalized( ):Angle( )

--Add some inaccuracy
ang:RotateAroundAxis( ang:Up( ), math.random( -4, 4 ) )
ang:RotateAroundAxis( ang:Right( ), math.random( -4, 4 ) )

bullet.Dir = ang:Forward( )



Something like that.

this works well when i have one bot spawned, but if i have multiple if the same bot, they start to shoot at each other for some reason

i have:


self.ang = (self:GetEnemy():GetPos() - self:GetPos()):GetNormalized():Angle()
bullet.Dir = self.ang:Forward() 


The bots both face me, but the bullets fire at each other, and they end up killing each other, rather than hitting me at all.
i have my bots print their enemy when they fire bullets, but it’s always my username that they print.

They ignore other bots however, they only shoot at their own kind.

?