View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:23 am



Reply to topic  [ 3 posts ] 
 Long Range Aiming Powered With Lua 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Tue Jun 14, 2011 3:22 am
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post 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


Tue Jun 14, 2011 5:07 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Wed Jun 15, 2011 1:52 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.081s | 13 Queries | GZIP : Off ]