View unanswered posts | View active topics It is currently Fri Dec 27, 2024 11:17 pm



Reply to topic  [ 7 posts ] 
 Radial outward force? 
Author Message
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post Radial outward force?
So yeah, i was working on making a radial shockwave yesterday, but to no avail. Whenever i think of something, it either fails or totally loses all coherence when i think it through, which kinda sucks. I want the script to launch any near particles away, in a direct line from the users center. The velocity that they're launched with depends on their distance from the center, the closer the faster. I've made it so that they fly faster the further they are away, but i'm unsure as to how i should reverse it to the previously stated function.
The script (for pushing actors) looks like this:
Code:
      for actor in MovableMan.Actors do
         local avgx = actor.Pos.X - self.Pos.X;
         local avgy = actor.Pos.Y - self.Pos.Y;
         local distx = math.sqrt((actor.Pos.X - self.Pos.X)^2);
         local disty = math.sqrt((actor.Pos.Y - self.Pos.Y)^2);
         local dist = math.sqrt(distx ^ 2 + disty ^ 2);
         local a = disty;
         local b = distx;
         local c = dist;
         if dist < 100 then
            if avgx > 0 then
               actor.Vel.X = (c/2) - (math.sqrt(c^2 - b^2)/2);
            elseif avgx < 0 then
               actor.Vel.X = -((c/2) - (math.sqrt(c^2 - b^2)/2));
            end
            if avgy > 0 then
               actor.Vel.Y = (c/2) - (math.sqrt(c^2 - a^2)/2);
            elseif avgy < 0 then
               actor.Vel.Y = -((c/2) - (math.sqrt(c^2 - a^2)/2));
            end
         end
      end

I'm pretty sure i need to subtract the above formula (math.sqrt(c^2...)) from some kind of value, but i just don't know which one. If you could help with this problem, it'd be greatly appreciated.


Fri Aug 21, 2009 5:30 pm
Profile WWW
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: Radial outward force?
Here's my basic function (taken from Bbl) for pushing things away.
Code:
   for particle in MovableMan.Actors do
      local avgx = particle.Pos.X - self.Pos.X;
      local avgy = particle.Pos.Y - (self.Pos.Y - 12);
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if dist <= 100 then
         local normal = math.atan2(-((self.Pos.Y - 12) - particle.Pos.Y), (self.Pos.X - particle.Pos.X));
         local particleHeading = math.atan2(-(particle.Vel.Y), (particle.Vel.X));
         if math.abs((normal + (3/2 * math.pi)) - (particleHeading + (3/2 * math.pi))) <= (math.pi/2) then
            local impulseVector = Vector(avgx, avgy);
            impulseVector:SetMagnitude(particle.Mass * 2 * particle.Vel.Magnitude);
            local zeroVector = Vector(0, 0);
            particle:AddAbsImpulseForce(impulseVector, zeroVector);
         end
      end
   end


Then, just modify the SetMagnitude line to set it proportional to the distance.
Code:
impulseVector:SetMagnitude(particle.Mass * (1 / dist) * 10);

I think that should do it...

EDIT: Whoops, forgot to take out the dist > 40 bit.
EDIT2: Whoops again, forgot to 1/dist.


Fri Aug 21, 2009 6:28 pm
Profile
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post Re: Radial outward force?
Sweet, thanks! I'll try it out tomorrow, because for now, i'm tired and sleepy and whatnot. Seems like some scary math, so it's no wonder that i couldn't figure it out. =P


Fri Aug 21, 2009 11:49 pm
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Radial outward force?
Uh... Well, Duh, would you allow me to use that too? I've spent the last few days trying to make a pushing script, and failed miserably... :roll:


Sat Aug 22, 2009 12:03 am
Profile WWW
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: Radial outward force?
Sure, go ahead.


Sat Aug 22, 2009 12:14 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Radial outward force?
Orbit Lands' GravitateMovableObject is great in this kind of situation as I've tweaked it to apply less force depending on the object's distance and stuff. You would have to reverse some of the coding though, so if you're less Lua-inclined, Duh's script is definitely a better option.


Sat Aug 22, 2009 1:15 am
Profile WWW
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post Re: Radial outward force?
Meh, i decided to scrap the idea in favor of an MOPixel shockwave, but thanks for your help, guys. Much appreciated. :)


Sat Aug 22, 2009 3:12 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.073s | 15 Queries | GZIP : Off ]