Data Realms Fan Forums http://45.55.195.193/ |
|
Radial outward force? http://45.55.195.193/viewtopic.php?f=73&t=16310 |
Page 1 of 1 |
Author: | Shook [ Fri Aug 21, 2009 5:30 pm ] |
Post subject: | 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. |
Author: | Duh102 [ Fri Aug 21, 2009 6:28 pm ] |
Post subject: | 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. |
Author: | Shook [ Fri Aug 21, 2009 11:49 pm ] |
Post subject: | 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 |
Author: | Areku [ Sat Aug 22, 2009 12:03 am ] |
Post subject: | 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... |
Author: | Duh102 [ Sat Aug 22, 2009 12:14 am ] |
Post subject: | Re: Radial outward force? |
Sure, go ahead. |
Author: | TheLastBanana [ Sat Aug 22, 2009 1:15 am ] |
Post subject: | 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. |
Author: | Shook [ Sat Aug 22, 2009 3:12 pm ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |