View unanswered posts | View active topics It is currently Sat Dec 28, 2024 4:41 pm



Reply to topic  [ 10 posts ] 
 Bullet Time Bomb (W.I.P) 
Author Message
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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.

Image

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

    Version 1.1
    - A few optimizations of code
    - Slightly less laggy
    - Time particles now stay in place rather than drift around randomly

    Current Issues
    - 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)


Attachments:
TimeSphere.rte.rar [193.43 KiB]
Downloaded 161 times
File comment: Version 1.1 with a few optimizations and a simple and efficient way to keep the particle in place
TimeSphere.rte.zip [45 KiB]
Downloaded 174 times


Last edited by ryry1237 on Tue Jan 10, 2012 12:50 pm, edited 5 times in total.

Sat Jan 07, 2012 9:11 am
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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.


Sat Jan 07, 2012 6:59 pm
Profile
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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.


Sun Jan 08, 2012 3:14 am
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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.


Sun Jan 08, 2012 3:12 pm
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post 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):


Last edited by Xery on Tue Jan 10, 2012 12:48 pm, edited 1 time in total.



Sun Jan 08, 2012 4:20 pm
Profile

Joined: Fri Dec 30, 2011 3:33 am
Posts: 276
Reply with quote
Post 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


Tue Jan 10, 2012 8:52 am
Profile
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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
Great stuff! I'll keep these things in mind when finding ways to optimize the lua.
Would it be ok if I just directly wrote
Code:
for particle/item in MovableMan.Particles/Items do
with the "/" and all?

Finally, is there any difference between
Code:
particles in MovableMan.Particles
and
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


Tue Jan 10, 2012 1:14 pm
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post 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.


Tue Jan 10, 2012 1:43 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
with the "/" and all?

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.


Wed Jan 11, 2012 5:16 am
Profile
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post Re: Bullet Time Bomb (W.I.P)
*slaps face in realization*

So that's how it worked.


Wed Jan 11, 2012 6:59 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.042s | 15 Queries | GZIP : Off ]