vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
|
| 14 May 2016 08:07 PM |
script.Parent.ExplosionHitbox.Touched:connect(function(p) wait(0.03) script.Parent.ExplosionHitbox.Anchored = true print(p.Name) if p.Name ~= "Explosion" then local pos = script.Parent.ExplosionHitbox.Position script.Parent:Destroy() local origPos = p.Position local origSize = p.Size local x = origSize.X/3 local y = origSize.Y/3 local z = origSize.Z local xs = origPos.X local x1 = xs - x local ys = origPos.Y local y1 = ys - y local zs = origPos.Z local positions = {Vector3.new(x1, y1, zs), Vector3.new(x1 + x, y1, zs), Vector3.new(x1 + (2 * x), y1, zs), Vector3.new(x1, ys, zs), Vector3.new(x1 + x, ys, zs), Vector3.new(x1 + (2 * x), ys, zs), Vector3.new(x1, ys + y, zs), Vector3.new(x1 + x, ys + y, zs), Vector3.new(x1 + (2 * x), ys + y, zs)} local i = 1 p:Destroy() while i <= 9 do wait() local part = Instance.new("Part") part.Anchored = false part.Name = "k" part.Parent = workspace part.Position = positions[i] part.CanCollide = true part.Size = Vector3.new(x, y, z) i = i + 1 end end end)
alright so this script fragments the block my custom explosion hits into 9 equally sized parts. of those 9 parts, I would like it to destroy the part the explosion is closest to, but I don't have any idea of how to do that.
can anyone give me a tip, or at least and idea about how to do that? if this was confusing to you, just tell me what confused you and ill try to clarify a bit more |
|
|
| Report Abuse |
|
|
Yamno
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 123 |
|
|
| 14 May 2016 08:11 PM |
| (positionA - positionB).magnitude gives the distance between point A and B. In all of the nine blocks, you could find the one with the shortest distance from the center of the part to the explosion position. |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
|
| 14 May 2016 08:14 PM |
| ive already tried something similar, but I think the problem is that it doesn't know which one that part is, since all the parts are identical |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
| |
|
|
| 14 May 2016 08:30 PM |
local distances = {}
for i=1, #positions do table.insert(distances, (script.Parent.ExplosionHitbox.Position - positions[i]).magnitude) end
table.sort(distances)
local longestDistance = distances[#distances] |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
|
| 14 May 2016 08:39 PM |
| alright, I got that, but how can I find the part that matches up to each distance? |
|
|
| Report Abuse |
|
|
|
| 14 May 2016 08:43 PM |
for i=1, #positions do if (positions[i] - script.Parent.ExplosionHitbox).magnitude == longestDistance then -- destroy part break end end |
|
|
| Report Abuse |
|
|
|
| 14 May 2016 08:44 PM |
correction:
for i=1, #positions do if (positions[i] - script.Parent.ExplosionHitbox.Position).magnitude == longestDistance then -- destroy part break end end |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
| |
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
|
| 15 May 2016 09:40 AM |
| that still doesn't help me find the part that matches up with each distance, I don't think |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
| |
|