Long Range Aiming Powered With Lua
Basically that.
This is my code so far:
Code:
function Create(self)
self.AimTimer = Timer()
end
function Update(self)
if self:GetController():IsPlayerControlled(-1) == false and self.AimTimer:IsPastSimMS(3700) then
local curdist = 2700
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < curdist and actor.PresetName ~= "Tesla Coil Dome" and actor.Team ~= self.Team then
self.target = actor;
end
end
self.NewAim = SceneMan:ShortestDistance(self.Pos,self.target.Pos,SceneMan.SceneWrapsX)
self:SetAimAngle(self.NewAim.AbsRadAngle)
if self.target ~= nil then
self:GetController():SetState(0,true)
self.target = nil
self.AimTimer:Reset()
end
end
end
So, what it does is check for the closest actor in a distance of 2700, calculate the vector, make that vector the aim angle of the turret and then it fires.
But it's not working, and I'm not sure why. I get the error of "target = nil", which is an expectable one when there is no actor near. But other than that, it seems like the code is not doing a thing.