Author |
Message |
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
It still gets fired upright. But now the trail changes direction when the particle hits something.
|
Sat Aug 08, 2009 11:24 am |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
Re: Lua trails?
Code: function Create(self) lastposx = self.Pos.X; lastposy = self.Pos.Y; lastpos = vector(lastposx,lastposy); counter = 0; numparticles=6; end function Update(self) local temp = Vector(self.Pos - lastpos); dist = temp.Magnitude; angle = math.atan(self.Vel.Y/self.Vel.X); spread = dist / numparticles; while (counter < numparticles) do counter = counter + 1; trail = CreateMOPixel("yourparticle"); trail.Pos.X = lastposx + (counter * (math.cos(angle) * spread)); trail.Pos.Y = lastposy + (counter * (math.sin(angle) * spread)); 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; lastposx = vector(lastposx,lastposy); end okay I went through the code on a piece of paper and I'm pretty sure that it works and that the only thing that could be wrong is the distance which before was very wrong? also I got the angle wrong, it should be angle = math.atan(self.Vel.Y/self.Vel.X); got the x and y mixed up this is roughly how it should work: http://filesmelt.com/downloader/scan008.png
|
Sat Aug 08, 2009 4:17 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
/ignore this post - Disregard this. I get the following: What does it mean? I don't know... Something with the Vector... Stupid lua GRAAHHHHH!!!!!! FFFFFFFFFFFF----!!!!!!
|
Sat Aug 08, 2009 7:30 pm |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
Re: Lua trails?
Code: function Create(self) lastposx = self.Pos.X; lastposy = self.Pos.Y; lastpos = vector(lastposx,lastposy); counter = 0; numparticles=6; end function Update(self) local temp = self.Pos - lastpos; dist = temp.Magnitude; angle = math.atan(self.Vel.Y/self.Vel.X); spread = dist / numparticles; while (counter < numparticles) do counter = counter + 1; trail = CreateMOPixel("yourparticle"); trail.Pos.X = lastposx + (counter * (math.cos(angle) * spread)); trail.Pos.Y = lastposy + (counter * (math.sin(angle) * spread)); 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; lastposx = vector(lastposx,lastposy); end pfft, k that's fixed fo' sho'
|
Sat Aug 08, 2009 11:07 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
|
Tue Aug 11, 2009 9:43 am |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
Re: Lua trails?
hehehe local temp = Vector(0,0); temp = self.Pos - lastpos;
if that doesn't work local tempx = self.Pos.X - lastposx; local tempy = self.Pos.Y - lastposy; local temp = Vector(tempx,tempy);
man vectors sure are stubborn
|
Tue Aug 11, 2009 3:28 pm |
|
|
LowestFormOfWit
Joined: Mon Oct 06, 2008 2:04 am Posts: 1559
|
Re: Lua trails?
If I was robolee, I'd be intentionally screwing up code just to see Maxim post more nerdrage pictures.
|
Tue Aug 11, 2009 3:30 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
LowestFormOfWit wrote: If I was robolee, I'd be intentionally screwing up code just to see Maxim post more nerdrage pictures. @ lee Nope, sire, that doesn't work. Are you even sure it has something to do with the 'temp' part?
|
Tue Aug 11, 2009 3:44 pm |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
Re: Lua trails?
I'm not really sure where any of the errors are that you encounter, based on what you tell me I have to take my best guess, and you're tellin me it's a problem with vectors... hey wait a second I see what I done wrong: in the create code I wrote: lastpos = vector(lastposx,lastposy); and at the end of the code: lastposx = vector(lastposx,lastposy);
change both to: lastpos = Vector(lastposx,lastposy);
stupid capitalism and hermit "x"'s. though I would expect you to notice that, you might want to check for silly errors like that yourself.
|
Wed Aug 12, 2009 1:11 am |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
robolee wrote: I'm not really sure where any of the errors are that you encounter, based on what you tell me I have to take my best guess, and you're tellin me it's a problem with vectors... hey wait a second I see what I done wrong: in the create code I wrote: lastpos = vector(lastposx,lastposy); and at the end of the code: lastposx = vector(lastposx,lastposy);
change both to: lastpos = Vector(lastposx,lastposy);
stupid capitalism and hermit "x"'s. though I would expect you to notice that, you might want to check for silly errors like that yourself. Actually, I did notice it, and I capitilized it. I thought you would too. >__________>' I'll see if that works. Edit: Well... It 'almost' works propely. (Hooray for it actually working ) I'll whoop a gif when I get back from work...
|
Wed Aug 12, 2009 3:46 am |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
Damnit! I totally forgot about this carp! Yeah, here's what happens now... It sorta semi works, and yet, it doesn't... Do you think that there may be a simpler yet effective-er code? Making something simple like a trail should not be so difficult >_____________________>' Shame there is no way to add a dragging glow to a MOP trail. Like, doing all this crap directly from the .ini.
|
Sun Aug 16, 2009 7:44 pm |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: Lua trails?
Maybe what you can do is modify the current code to spawn a line of glows, instead of just the one. Something like Code: for i = 0 to AMT (spawn glow at) Vector(self.Pos.X - i * (currentPos - lastPos / AMT), self.Pos.Y - i * (currentPos - lastPos / AMT)) end
|
Sun Aug 16, 2009 7:51 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Lua trails?
Seriously this could all be done with sin and cos. Just spawn three particles per sim update, one at self pos, and then one each at 5 pixels forward and back along the velocity vector.
|
Sun Aug 16, 2009 10:26 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Lua trails?
Grif wrote: Seriously this could all be done with sin and cos. Just spawn three particles per sim update, one at self pos, and then one each at 5 pixels forward and back along the velocity vector. I'd do it. Sadly though, I haven't quite mastered all the trig and ♥♥♥♥ yet. Actually, I can't understand how it even works. >_______________>'
|
Sun Aug 16, 2009 11:00 pm |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: Lua trails?
Grif wrote: Seriously this could all be done with sin and cos. Oooor, you could use the X and Y of a normalized copy of the velocity vector multiplied by some constant, and negate it for the one behind...
|
Sun Aug 16, 2009 11:09 pm |
|
|
|