View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:12 pm



Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
 Boids Troubles - Help Please 
Author Message

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Boids Troubles - Help Please
So basically what it tries to do is create 4 boids when you fire (including self).

But after a little bit of boiding around, they all drift apart from eachother, even
though you can see the muzzleflashes are pointing in different directions than
where they are drifting.

Why does the emitting suddenly stop pushing the emitter?


Attachments:
File comment: This is a little more complicated than just showing you the code.
Boids.rte.rar [3.02 KiB]
Downloaded 213 times
Fri Jul 31, 2009 9:18 pm
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Boids Troubles - Help Please
This is the only emission that I saw with a PushesEmitter = 1. It's set to stop emitting after 3 seconds.
Code:
   AddEmission = Emission
      EmittedParticle = MOPixel
         CopyOf = Air Blast
      ParticlesPerMinute = 2000
      StartTimeMS = 500
      StopTimeMS = 3000
      BurstSize = 2
      Spread = 0.5
      MaxVelocity = 3
      MinVelocity = 3
      PushesEmitter = 1


Sat Aug 01, 2009 7:17 am
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Boids Troubles - Help Please
Awesome. It works!

Btw is there a way to make them just Orient to Velocity upon
spawning so I won't have to use that "OrienttoVel" variable
that messes it up?


Mon Aug 03, 2009 5:42 pm
Profile WWW
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Boids Troubles - Help Please
in function create(Self)
self.RotAngle = math.atan(self.Vel.X/self.Vel.Y);
?


Mon Aug 03, 2009 6:14 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Boids Troubles - Help Please
Cool, all I need to do is make it so you can dynamically keep adding Boids to the system.

Thanks guys *Off to learn tables and stuff*.


Tue Aug 04, 2009 4:02 am
Profile WWW

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Boids Troubles - Help Please
How can I go through an Array/Table and add together all of
a variable from the objects from that table so then I can divide
that by the number of objects in the table? :grin:


Tue Aug 04, 2009 6:20 am
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Boids Troubles - Help Please
for pointer in table do
local sum = sum + pointer.value;
local average = sum / getn(table);
end


Tue Aug 04, 2009 6:58 am
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Boids Troubles - Help Please
Code:
function Create(self)
    if BoidList == nil then
   BoidList = { };
    end
    self.ListNumber = #BoidList + 1;
    BoidList[#BoidList + 1] = self;

   local DirAway = 0;
   local AvgDir = 0;
   local targetdir = 0;
   local DirSum = 0;
   local PosSum = 0;
   self.RotAngle = math.atan(self.Vel.X/self.Vel.Y);
end


function Update(self)
       for i=1, #BoidList do
       if MovableMan:IsParticle(BoidList[i]) then

    for Particle in BoidList do
      local avgx = Particle.Pos.X - self.Pos.X;
      local avgy = Particle.Pos.Y - self.Pos.Y;
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if dist < 20 then
         DirAway = -(math.atan2(-(Particle.Pos.Y-self.Pos.Y),(Particle.Pos.X-self.Pos.X)));
      end
    end

   local DirSum = 0;
      DirSum = DirSum + BoidList[i].RotAngle;
      AvgDir =  DirSum / #BoidList;

   local PosSum = 0;
      PosSum = PosSum + BoidList[i].Pos;
      AvgPos =  PosSum / #BoidList;

   local DirToCenter = math.atan2(-(AvgPos.Y-self.Pos.Y),(AvgPos.X-self.Pos.X));
   local targetdir = (DirToCenter + AvgDir + DirAway) / 3;

   if targetdir ~= self.RotAngle then
      self.RotAngle = targetdir;
   end

       --Make sure the missile's thruster is firing.
       if self:IsEmitting() == false then
           self:EnableEmission(true);
       end
   end
   end
end

function Destroy(self)
   BoidList[self.ListNumber] = nil;
end


"Attempted to get Value from Table! Line 21"
I want it to get a value from a table! Why is that so wrong?!
Btw Line 21 is:
Code:
    for Particle in BoidList do


Tue Aug 04, 2009 5:20 pm
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Boids Troubles - Help Please
Pretty sure it needs to be self.BoidList, not just BoidList


Tue Aug 04, 2009 6:04 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Boids Troubles - Help Please
Well, I managed to fix the above piece of code using some TLB magic, but there are still some problems.

Image
http://i34.photobucket.com/albums/d144/ ... ump020.jpg

I fixed the table part, but didn't touch anything else, so what's up?


Tue Aug 04, 2009 10:33 pm
Profile WWW

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Boids Troubles - Help Please
More progress, still broken:

Code:
function Create(self)
    if BoidList == nil then
   BoidList = { };
    end
    self.ListNumber = #BoidList + 1;
    BoidList[#BoidList + 1] = self;

   local DirAway = 0;
   local AvgDir = 0;
   local targetdir = 0;
   local DirSum = 0;
   local PosSum = Vector(0,0);
--   local PosSum.X = 0;
--   local PosSum.Y = 0;
   local AvgPos = Vector(0,0);
--   local AvgPos.X = 0;
--   local AvgPos.Y = 0;
   self.RotAngle = math.atan(self.Vel.X/self.Vel.Y);
end


function Update(self)
       for i=1, #BoidList do
       if MovableMan:IsParticle(BoidList[i]) then
      local avgx = BoidList[i].Pos.X - self.Pos.X;
      local avgy = BoidList[i].Pos.Y - self.Pos.Y;
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if dist < 20 then
         DirAway = -(math.atan2(-(BoidList[i].Pos.Y-self.Pos.Y),(BoidList[i].Pos.X-self.Pos.X)));
      end


   local DirSum = 0;
      DirSum = DirSum + BoidList[i].RotAngle;
      AvgDir =  DirSum / #BoidList;

   local PosSum = Vector(0,0);
--      PosSum = PosSum + BoidList[i].Pos;
      PosSum.X = PosSum.X + BoidList[i].Pos.X;
      PosSum.Y = PosSum.Y + BoidList[i].Pos.Y;
--      AvgPos =  PosSum / #BoidList;
      AvgPos.X = PosSum.X / #BoidList;
      AvgPos.Y = PosSum.Y / #BoidList;

   local DirToCenter = math.atan2(-(AvgPos.Y-self.Pos.Y),(AvgPos.X-self.Pos.X));
   local targetdir = (DirToCenter + AvgDir + DirAway) / 3;

   if targetdir ~= self.RotAngle then
      self.RotAngle = targetdir;
   end

       --Make sure the missile's thruster is firing.
       if self:IsEmitting() == false then
           self:EnableEmission(true);
       end
   end
   end
end

function Destroy(self)
   BoidList[self.ListNumber] = nil;
end


Line 39 Attempting to call Global PosSum (A nil Value!)
Line 39: PosSum.X = PosSum.X + BoidList[i].Pos.X;
:???:


Thu Aug 06, 2009 6:43 am
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Boids Troubles - Help Please
A local created in create is only accessible in create afaik.


Thu Aug 06, 2009 2:27 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Boids Troubles - Help Please
use self.PosSum instead of local.


Thu Aug 06, 2009 9:37 pm
Profile WWW
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Boids Troubles - Help Please
only use local if you only want the variable to be accessed in the if loop it is in as it gets deleted at the end of the loop.


Fri Aug 07, 2009 7:57 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Boids Troubles - Help Please
*block but hey who's counting


Fri Aug 07, 2009 9:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 16 posts ]  Go to page 1, 2  Next

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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.326s | 14 Queries | GZIP : Off ]