Data Realms Fan Forums
http://45.55.195.193/

Early detonation.
http://45.55.195.193/viewtopic.php?f=1&t=31925
Page 1 of 1

Author:  Ganenge [ Thu Oct 11, 2012 5:13 pm ]
Post subject:  Early detonation.

How do you code a projectile to detonate when it reaches a certain distance?

Author:  p3lb0x [ Thu Oct 11, 2012 5:34 pm ]
Post subject:  Re: Early detonation.

Each frame, add the distance traveled to some counter, when the counter goes over a specified amount, explode.

Code:
function Create(self)

self.distancecounter = 0;
self.explodedistance = 1000;
self.lastpos = self.Pos;
self.tempvector = Vector(0,0);

end
function Update(self)

self.tempvector = self.lastpos - self.Pos
self.distancecounter = self.distancecounter + self.tempvector.Magnitude

if self.distancecounter > self.explodedistance then

insert explosion lua here or go with
self:GibThis();

end

self.lastpos = self.Pos;
end


Might work, untested though.

Author:  Ganenge [ Thu Oct 11, 2012 8:36 pm ]
Post subject:  Re: Early detonation.

ah thanks, now I have extra time to get fustrated over my bad art skills.

Author:  Bad Boy [ Thu Oct 11, 2012 10:24 pm ]
Post subject:  Re: Early detonation.

That seems like a kind of convoluted way to do it when this will suffice. Essentially it's the same thing as p3lb0x's but in fewer lines. Note that it's untested though it should work fine unless I typoed somewhere.
Code:
function Create(self)
   self.StartPos = self.Pos; --A variable containing its starting position
   self.ExplodeDist = 1000; --A variable that sets how far the projectile can go before exploding
end
function Update(self)
   --If the magnitude of its start and its current position are greated than the set explosion distance, explode it.
   if (self.Pos - self.StartPos).Magnitude >= self.ExplodeDist then
      self:GibThis();
   end
end
function Destroy(self)
end

Author:  p3lb0x [ Thu Oct 11, 2012 10:28 pm ]
Post subject:  Re: Early detonation.

The only problem I can see with that way bad boy is that it would just be a straight line to the position it was spawned at. where as the way I am doing it you would end up with the arc it flies in. I can see that I wouldn't need the temporary vector though, I didn't know you could do what you did.

Author:  Bad Boy [ Fri Oct 12, 2012 1:16 am ]
Post subject:  Re: Early detonation.

Oh yeah, you're absolutely right, I was just thinking of it as a straight line. Just goes to show how little I actually script for weapons and stuff in CC.
So yeah, assuming the bullet arcs (and you want it to be accounted for rather than it just measuring the distance difference) go with p3l's method and trim it down if you feel inclined.

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