Author |
Message |
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Lua trails?
Either or, really. PS, MD, try this: http://pastebin.com/m2bfe1659
|
Sun Aug 16, 2009 11:56 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
Error at line 7: 'Bad argument #1 to 'atan2' (number expected, got userdata)'
|
Mon Aug 17, 2009 12:00 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
It sorta kinda works, though I get this: 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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
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 |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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 |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Lua trails?
robolee you're using globals on an automatic weapon
|
Tue Aug 18, 2009 5:48 pm |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Lua trails?
http://lua.lickert.net/variable/index_en.htmlQuote: 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 |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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 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 |
|
|
|