Data Realms Fan Forums
http://forums.datarealms.com/

Long Range Aiming Powered With Lua
http://forums.datarealms.com/viewtopic.php?f=73&t=24229
Page 1 of 1

Author:  Asklar [ Tue Jun 14, 2011 3:22 am ]
Post subject:  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.

Author:  Xery [ Tue Jun 14, 2011 5:07 am ]
Post subject:  Re: Long Range Aiming Powered With Lua

Code:
 if 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 not self:IsPlayerControlled() and actor.PresetName ~= "Tesla Coil Dome" and actor.PresetName ~= self.PresetName and actor.Team ~= self.Team then
    self.target = actor;
   end
  end
  if self.target ~= nil then
   self.NewAim = SceneMan:ShortestDistance(self.Pos,self.target.Pos,SceneMan.SceneWrapsX);
   self:SetAimAngle(self.NewAim.AbsRadAngle);
   self:GetController():SetState(14,true);
   self.target = nil;
   self.AimTimer:Reset();
  end
 end


It shows no error but still have some problem.
You may want to have a look at this: viewtopic.php?f=73&t=21432

Author:  Asklar [ Wed Jun 15, 2011 1:52 am ]
Post subject:  Re: Long Range Aiming Powered With Lua

Set state 14? Wasn't 0 for primary action?

EDIT:
By the way, the code in that thread you posted, I already had thought something similar to make it's aiming more precise, considering some factors like distance between target and self, proyectile speed, target speed, etc.
But I would probably need some help on that, because the bullet this thing fires goes in a straight line, it's not affected by gravity or air resistance or stuff, and it's speed is variable.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/