View unanswered posts | View active topics It is currently Sat Jun 15, 2024 11:40 pm



Reply to topic  [ 6 posts ] 
 Early detonation. 
Author Message

Joined: Sat Oct 06, 2012 11:30 pm
Posts: 12
Reply with quote
Post Early detonation.
How do you code a projectile to detonate when it reaches a certain distance?


Thu Oct 11, 2012 5:13 pm
Profile
Forum Moderator
User avatar

Joined: Fri Feb 02, 2007 3:53 pm
Posts: 1896
Location: in my little gay bunker
Reply with quote
Post 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.


Thu Oct 11, 2012 5:34 pm
Profile

Joined: Sat Oct 06, 2012 11:30 pm
Posts: 12
Reply with quote
Post Re: Early detonation.
ah thanks, now I have extra time to get fustrated over my bad art skills.


Thu Oct 11, 2012 8:36 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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


Thu Oct 11, 2012 10:24 pm
Profile
Forum Moderator
User avatar

Joined: Fri Feb 02, 2007 3:53 pm
Posts: 1896
Location: in my little gay bunker
Reply with quote
Post 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.


Thu Oct 11, 2012 10:28 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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.


Fri Oct 12, 2012 1:16 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.064s | 13 Queries | GZIP : Off ]