Data Realms Fan Forums http://45.55.195.193/ |
|
Bullet Time Bomb (W.I.P) http://45.55.195.193/viewtopic.php?f=1&t=29105 |
Page 1 of 1 |
Author: | ryry1237 [ Sat Jan 07, 2012 9:11 am ] | |||
Post subject: | Bullet Time Bomb (W.I.P) | |||
I've been messing around with Lua scripting quite a bit recently in a new little project of mine. It's supposed to be a bomb used to protect people inside from projectile based weapons. It currently lags a bit, especially when you use a concrete sprayer on the thing, so code optimization is one of the main things I'm looking into now. I'm also trying to figure out how to make this a personal "weapon" that can be activated with the push of a button, so if any experienced modders can give advice, I'd be happy to listen. File should be compatible with all B23+ versions
- A few optimizations of code - Slightly less laggy - Time particles now stay in place rather than drift around randomly
- Laggy if too much stuff gets into it (Solved) Still looking for efficient ways to keep object in place - Actors aren't affected by the bomb (intentional) but their gibbed body parts are (major source of lag)
|
Author: | Duh102 [ Sat Jan 07, 2012 6:59 pm ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
Making the effect stay in place is pretty easy, just add a variable self.position to the create() function and set your position to that every update(). Code: function Create(self) self.position = {self.Pos.X, self.Pos.Y}; end function Update(self) self.Pos = self.position; end As for making it into a device, are you wanting it to toggle when fired and follow the user around, or act like a grenade launcher for these grenades? The toggle method would be a bit harder, the grenade launcher method is pretty easy. Just make the TDExplosive you have now into a MOSRotating, then grab the code for one of the guns in the vanilla data and replace one of their Round statement's shot particle lines with your MOSRotating. |
Author: | ryry1237 [ Sun Jan 08, 2012 3:14 am ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
Thanks, although I heard that using lua tends to cause lag (the little bit I'm using for the stopping effect certainly is). Ideally, I'd like to make it a toggleable (like press a key and it just follows the user around like a personal shield), but then there's the problem with not stopping the user's own bullets. Making it come out of a grenade launcher type weapon would work well too. I'm just mostly playing around with whatever looks and feels cool. |
Author: | Duh102 [ Sun Jan 08, 2012 3:12 pm ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
Lua lags in proportion to how much stuff you do with it. Doing trig every frame like you're doing (Update is called every frame, or almost) is a lot of calculation, so it will cause lag, but setting a position won't be too bad. But you have to play with it. |
Author: | Xery [ Sun Jan 08, 2012 4:20 pm ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
You can have a timer that set interval between two checks, which may cost a less smoothly "slow-down" effect(and needs you to increase the slow-down ratio every checks), but helps alot with the lag. And, if you don't want things within the area to fall down little by little, sceneMan:GetGlobalAcc helps, I think. Oh, and these lua code can let your shield only blocks things toward the centre of the shield(I've posted it several times before): |
Author: | xenoargh [ Tue Jan 10, 2012 8:52 am ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
Be careful to use some optimization to lose a lot of particles; just doing a rough sort can get rid of a lot of processing and make most of the lag go bye-bye. Branching is cheap in Lua, especially when it saves hundreds or thousands of math steps farther in the logic. Code: --localize everything we're going to use that can't be more efficiently localized in the loop here. local avgx = nil; local avgy = nil; local dist = nil; local part = nil; local selfTeam = self.Team; --This generates a huge list; start doing a sort, eliminate junk. for particle/item in MovableMan.Particles/Items do --Drop a whole bunch of particles here, and now your cool thing doesn't stop your team's shots if particle.HitsMOs == true and particle.Team ~= selfTeam then --Drop a lot of the rest of them here. if particle.PresetName ~= "your gun" then --if we pass both cheap boolean checks, then and only then do all this math --Trigonometry to find how far the particle is. avgx = particle.Pos.X - self.Pos.X; avgy = particle.Pos.Y - self.Pos.Y; dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < 300 then --slow down any enemy particles close to me fairly rapidly local velX = particle.Vel.X if velX > 0 then velX = math.max(velX - 5, 0) else velX = math.min(velX + 5, 0) end particle.Vel.X = velX; --repeat for Y, you're done end end end end |
Author: | ryry1237 [ Tue Jan 10, 2012 1:14 pm ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
Xery wrote: You can have a timer that set interval between two checks, which may cost a less smoothly "slow-down" effect(and needs you to increase the slow-down ratio every checks), but helps alot with the lag. And, if you don't want things within the area to fall down little by little, sceneMan:GetGlobalAcc helps, I think. Oh, and these lua code can let your shield only blocks things toward the centre of the shield(I've posted it several times before): Setting the script to check only once every several game calculations makes the particles inside the time bubble fall down section by section due to gravity whenever it's not checking. If there was a way to directly alter the GlobalAccScalar values of the objects (and not just its velocity on a single frame using sceneMan:GetGlobalAcc), then it might work more naturally. Unfortunately I don't know how, and the gravity gun mod which I'm basing some of my stuff off of doesn't use that method either. The code you've posted is pretty useful though, especially as a template for how to localize variables. xenoargh wrote: Be careful to use some optimization to lose a lot of particles; just doing a rough sort can get rid of a lot of processing and make most of the lag go bye-bye. Branching is cheap in Lua, especially when it saves hundreds or thousands of math steps farther in the logic. code Would it be ok if I just directly wrote Code: for particle/item in MovableMan.Particles/Items do Finally, is there any difference between Code: particles in MovableMan.Particles Code: target in MovableMan.Particles I'm using target in MovableMan.Particles to stop bullets just fine, so I'm not very sure if there's any difference between the two |
Author: | Xery [ Tue Jan 10, 2012 1:43 pm ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
xenoargh wrote: Be careful to use some optimization to lose a lot of particles; just doing a rough sort can get rid of a lot of processing and make most of the lag go bye-bye. Branching is cheap in Lua, especially when it saves hundreds or thousands of math steps farther in the logic. Good job and thx! I forgot to delete some of the codes that used to reflect things to reasonably directions and made them able to hit the shooter. |
Author: | Duh102 [ Wed Jan 11, 2012 5:16 am ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
ryry1237 wrote: Would it be ok if I just directly wrote Code: for particle/item in MovableMan.Particles/Items do It's the respective MovableMan list for the items in question, so you'd have to do it for particle in MovableMan.Particles and for item in MovableMan.Items. The lower case particle/item is just the reference you use inside the for loop, so you can call it whatever you like. for derp in MovableMan.Particles, for instance. |
Author: | ryry1237 [ Wed Jan 11, 2012 6:59 am ] |
Post subject: | Re: Bullet Time Bomb (W.I.P) |
*slaps face in realization* So that's how it worked. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |