View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:12 am



Reply to topic  [ 67 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
 Lua trails? 
Author Message
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua trails?
Either or, really.

PS, MD, try this:

http://pastebin.com/m2bfe1659


Sun Aug 16, 2009 11:56 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post Re: Lua trails?
Error at line 7: 'Bad argument #1 to 'atan2' (number expected, got userdata)'


Mon Aug 17, 2009 12:00 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua trails?
Yeah I realized that last night.

glow2.Pos = Vector(self.Pos.X + 5 * math.cos(math.atan2(self.Vel.Y,self.Vel.X)),self.Pos.Y + 5 * math.sin(math.atan2(self.Vel.Y,self.Vel.X)));

glow3.Pos = Vector(self.Pos.X - 5 * math.cos(math.atan2(self.Vel.Y,self.Vel.X)),self.Pos.Y - 5 * math.sin(math.atan2(self.Vel.Y,self.Vel.X)));

Replace line 7 and 9 with that and it should work.


Mon Aug 17, 2009 2:42 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post Re: Lua trails?
It sorta kinda works, though I get this:
Image

When the weapon is fired, you can't quite see the trail on the round, but when it hits something and stops you can clearly see it.
Maybe increasing the amount of particles would make it more noticable.

Oh, and when the bullet hits a wall the trail just rotates around it.
Would adding 'while (self.Vel.X > 1 and self.Vel.Y > 1) do' stop the creation of the trail when the round isn't moving?


Mon Aug 17, 2009 2:59 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua trails?
You don't need while for that, just use if, or, then.

Also Duh's suggestion would also work, probably somewhat better than this now that I think about it.

I might code it up later.


Mon Aug 17, 2009 3:11 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: Lua trails?
Grif wrote:
probably somewhat better than this now that I think about it.

I was just going for simplicity. All those sines and cosines can get confusing.


Mon Aug 17, 2009 4:48 pm
Profile
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Lua trails?
well this is rather perplexing. my code does do exactly what grif said ("Seriously this could all be done with sin and cos" and tan- they all give the exact same result) the only reason it's not that straightforward is because you have to store the current and previous locations to do trig on, and have to iterate through the code the desired amount of times... K I removed any vector crap if the following doesn't work I give up and blame some wacky lua math error

Code:
function Create(self)
   lastposx = self.Pos.X; lastposy = self.Pos.Y;
   counter = 0;
   numparticles=6;
   angle = 0;
   dist = 0;
end
function Update(self)
   angle = math.atan(self.Vel.Y/self.Vel.X);
   dist = (self.Vel.Y/math.sin(angle)) / numparticles;
   while (counter < numparticles) do
      counter = counter + 1;
      trail = CreateMOPixel("yourparticle");
      trail.Pos.X = lastposx + ( counter * ( math.cos(angle) * dist ) );
      trail.Pos.Y = lastposy + ( counter * ( math.sin(angle) * dist ) );
      trail.Vel = self.Vel;
      MovableMan:AddParticle(trail);
   end
   if (counter == numparticles) then counter = 0; end
   --anything else you want to add
   lastposx = self.Pos.X; lastposy = self.Pos.Y;
end


Tue Aug 18, 2009 5:06 am
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post Re: Lua trails?
Well, that works, but its still messy and all...
It does what it should, it follows the angle of the round and all that, but after a few shots I start having 'shotgun trails'.
The trail starts duplicating and it looks as if there were multiple particles fired simultaneously.
And its pretty buggy overall.... :/

Thanks for the help guys, but it just isn't what I was hoping to achieve. :/
I might use this for something else though.


Tue Aug 18, 2009 3:09 pm
Profile
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Lua trails?
you sure that's not cause by the gun (i.e try it without the lua script)


Tue Aug 18, 2009 5:23 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua trails?
robolee you're using globals on an automatic weapon


Tue Aug 18, 2009 5:48 pm
Profile
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Lua trails?
so scripts are global then? I had a feeling that could be what was happening but I was sure that all script variables were local to their script/object. I did wonder about adding self. to all the variables, so you should try that. (self.dist self.angle self.counter)


Tue Aug 18, 2009 5:55 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua trails?
http://lua.lickert.net/variable/index_en.html

Quote:
Variables are global, if they are not declared local.


Lua's weird that way. How have you not noticed that, ever?


Tue Aug 18, 2009 5:57 pm
Profile
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Lua trails?
I knew that, but I thought that CC handled scripts locally to objects (as in even though the variables are global they are attached to the object in a way that the script variables do not affect other scripts in any way)... basically if you've done any work on linked lists in C++ you'd understand where I was coming from.


Tue Aug 18, 2009 7:06 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua trails?
But these aren't linked lists, they're directly named variables in a script made in Lua which has its own peculiarities.

Also, the ♥♥♥♥ do you mean global yet not global? What would the point be of not having a way to send things from one script to another? And why would data bother going to the trouble of designing object-based local globals rather than just leaving it be and letting people make their OWN locals and globals.


Tue Aug 18, 2009 8:53 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post Re: Lua trails?
Grif wrote:
But these aren't linked lists, they're directly named variables in a script made in Lua which has its own peculiarities.

Also, the ♥♥♥♥ do you mean global yet not global? What would the point be of not having a way to send things from one script to another? And why would data bother going to the trouble of designing object-based local globals rather than just leaving it be and letting people make their OWN locals and globals.


Wait a second... Forget the trail and all this thread and whatnot...... What you are saying is that if I have 'Something = 1' on one script, I can have a 'if Something == 1 then' on another script and it will work without having to go over 'Something = 1' from the beginning??? \:|


Well FFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUUUUCCCCCCCCCCCCCCCCCKKKKKKKKKKKKKKKKKKK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If I knew this from the beginning my mod contest entry wouldn't be such a ♥♥♥♥ failure. >:E

♥♥♥♥ ♥♥♥♥ ♥♥♥♥ ♥♥♥♥ FUUUUUUUUUUUUCK!!!!! D:<

/rage
Image

BUT, this also means I can get rid of all the lag in my laser door!!! SO ♥♥♥♥ YEAH! >:D


Tue Aug 18, 2009 9:11 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 67 posts ]  Go to page Previous  1, 2, 3, 4, 5  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.097s | 14 Queries | GZIP : Off ]