Author |
Message |
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Script: Adding an AEmitter to a MOPixel.
Hello, And yet another request. I'd like to have the laser weapons in UniTec to actually look a bit like... lasers. But I'd like to keep MOPixels (or MOSParticles) as their round, since I find AEmitter rounds not really effective at hitting a target without creating some sort of an explosion. I wonder if it's possible to attach an AEmitter to a MOPixel through lua? If so, would anyone mind conjuring up a script to make this happen?
|
Wed Sep 07, 2011 1:53 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Script: Adding an AEmitter to a MOPixel.
Code: function Create(self) self.emitter = CreateAEmitter("<<Insert Emitter Name>>"); self.emitter.Pos = self.Pos; self.emitter.Vel = self.Vel; MovableMan:AddParticle(self.emitter) end
function Update(self) self.emitter.Pos = self.Pos; self.emitter.Vel = self.Vel; end It'd take a marginally more advanced script to rotate the emissions to accommodate the velocity of the bullet, but if you emit them at zero velocity in no particular direction this should look fine.
|
Wed Sep 07, 2011 6:38 pm |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Adding an AEmitter to a MOPixel.
Thanks, it works, but... after shooting around for a bit the game freezes repeatedly. And I see why. xD The emitters keep floating about after the bullets are gone. I tried adding this: Code: function Destroy(self) self.ToDelete = true; end but that was obviously too easy of me to think that would work.
|
Wed Sep 07, 2011 7:43 pm |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Adding an AEmitter to a MOPixel.
Any chance to show me a marginally more complicated script? I've got a laser glow emitter that looks like this: Attachment:
laser.png [ 21.15 KiB | Viewed 4121 times ]
but, as you said, the mopixels do not align well with the actual shot.
|
Wed Sep 07, 2011 8:15 pm |
|
|
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
|
Re: Script: Adding an AEmitter to a MOPixel.
What I would do is simply continuously add particles through lua and forget the emitter entirely. Code: function Update(self) self.particle = CreateMOPixel("<<Insert particle Name>>"); self.particle.Pos = self.Pos; self.particle.Vel = self.Vel; MovableMan:AddParticle(self.particle) end
Either leave off that vel line, or give the particles more airresistance than the scripted particle (which looks great for smoke trails, but for the laser you might want to just spawn it at zero vel, assuming once per lua update is a fast enough rate of spawning particles to make a continuous beam effect. If not, the AEmitter might be the better option.)
|
Wed Sep 07, 2011 8:23 pm |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Adding an AEmitter to a MOPixel.
Thanks, Azukki, but no matter what I try, it just leaves a trail like this: . . . . I'm afraid it's really necessary to use an emitter.
|
Wed Sep 07, 2011 9:05 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Script: Adding an AEmitter to a MOPixel.
Gotcha! wrote: Code: function Destroy(self) self.ToDelete = true; end You were really close. Code: function Destroy(self) self.emitter.ToDelete = true; end My bad for not putting it there in the first place.
|
Wed Sep 07, 2011 10:44 pm |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Adding an AEmitter to a MOPixel.
No worries. Anyway, as soon as I add a max- and minvelocity to the emitter's emision things aren't going as planned, and it's needed to make a long laserbolt. Instead of lining up they fly off to the right. Even when shooting to the left. :S Attachment:
ScreenDump001.png [ 195.35 KiB | Viewed 4101 times ]
|
Wed Sep 07, 2011 11:25 pm |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: Script: Adding an AEmitter to a MOPixel.
You'd have to calculate the "Angle" of the MOPixel using trigonometry and rotate the AEmitter to fit that.
|
Thu Sep 08, 2011 1:16 am |
|
|
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
|
Re: Script: Adding an AEmitter to a MOPixel.
Or just have OrientsToVel = 1 on the emitter's .ini. Might want to negative-ize the emission velocities, too, depending on whether you want the emissions in the same direction or opposite to the parent's vel. The speed can't correlate to the parent, though, which is why I'd forget about the emission and just Lua it, but whatever, it's your mod.
Last edited by Azukki on Thu Sep 08, 2011 1:54 am, edited 2 times in total.
|
Thu Sep 08, 2011 1:28 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: Script: Adding an AEmitter to a MOPixel.
That's a much simpler solution
|
Thu Sep 08, 2011 1:40 am |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Adding an AEmitter to a MOPixel.
Azukki wrote: The speed can't correlate to the parent, though, which is why I'd forget about the emission and just Lua it, but whatever, it's your mod. Don't overestimate my capabilities. If you can help with that, please do. Well, your OrientToVel tip did the trick. It needs some tinkering, but there's a glow trail present now. I struck into a weird problem though. The game freezing returned. When I fire the modified bullets into the ground or enemies the game freezes after a couple of shots. I'll try to find the cause of it, but somehow I'm afraid it's lua related. This is the script I have now: Code: function Create(self) self.emitter = CreateAEmitter("Laser Glow emitter"); self.emitter.Pos = self.Pos; self.emitter.Vel = self.Vel; MovableMan:AddParticle(self.emitter) end
function Update(self) self.emitter.Pos = self.Pos; self.emitter.Vel = self.Vel; end
function Destroy(self) self.emitter.ToDelete = true; end
|
Thu Sep 08, 2011 2:21 am |
|
|
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
|
Re: Script: Adding an AEmitter to a MOPixel.
That would be the result of the parent projectile referencing the emitter (in the update function) when the emitter is destroyed. It might be gibbing, lifetime, or settling, I have no idea, but I'm positive that the crash is happening because the parent wants to tell the emitter what to do at some point when the emitter is gone. You could try to make sure the emitter is completely invincible, but in those occasions where even the invincible is destroyed, you'd still get a crash. SO. Instead of telling the particle once "This is the emitter" and then continuously saying "keep it with you", continuously tell/ask the particle "Do you still have your emitter? If so, keep it with you, if you never had it, or if you lost it, here's an emitter" (if you have a reference to an object that once was but no longer exists, the ID is 255, or at least this works for everything else I've done) So try this. I haven't tested it because I don't feel like setting up the ini to do so, but I'm moderately confident that it's either functional or very close to functional. Code: function Update(self) if self.emitter then if self.emitter.ID ~= 255 then self.emitter.Pos = self.Pos self.emitter.Vel = self.Vel else self.emitter = CreateAEmitter("Laser Glow emitter") self.emitter.Pos = self.Pos self.emitter.Vel = self.Vel MovableMan:AddParticle(self.emitter) end else self.emitter = CreateAEmitter("Laser Glow emitter") self.emitter.Pos = self.Pos self.emitter.Vel = self.Vel MovableMan:AddParticle(self.emitter) end end
function Destroy(self) if self.emitter.ID ~= 255 then self.emitter.ToDelete = true end end I think you're overestimating the difficulty of spawning the particles in Lua. It's easier than doing the above. My script should have only needed some minor tweaks to get the spacing you want, unless it was vital that the particles not inherit velocity, but that's obviously not the case since you have emission velocities. When you tried it before, the only problem was that the particles spawned were too far apart, yes? Code: function Update(self) self.particle = CreateMOPixel("<<Insert particle Name>>") self.particle.Pos = self.Pos self.particle.Vel = self.Vel * 0.9 MovableMan:AddParticle(self.particle) end How about that, with no airresistance on the particles? Too far apart still? Increase 0.9 (not to or beyond 1, though). Too close? Decrease 0.9 Too short of a trail? Increase particle lifetime. Too long? Decrease lifetime.
|
Thu Sep 08, 2011 4:15 am |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Adding an AEmitter to a MOPixel.
Thanks, your second script did it. Not perfectly, but I think I might be chasing rainbows. The first script, I couldn't get it right, but I don't think it's the script. Probably my wonkey emitter. I am very happy. Cake for you!
|
Thu Sep 08, 2011 2:29 pm |
|
|
|