generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: fragmentation

Previous Thread :: Next Thread 
vastqud is not online. 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 is not online. 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 is not online. 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 is not online. vastqud
Joined: 10 Sep 2011
Total Posts: 2464
14 May 2016 08:20 PM
any help with that?
Report Abuse
Immersible is not online. Immersible
Joined: 14 Aug 2015
Total Posts: 432
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 is not online. 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
Immersible is not online. Immersible
Joined: 14 Aug 2015
Total Posts: 432
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
Immersible is not online. Immersible
Joined: 14 Aug 2015
Total Posts: 432
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 is not online. vastqud
Joined: 10 Sep 2011
Total Posts: 2464
14 May 2016 10:01 PM
ok thanks fam
Report Abuse
vastqud is not online. 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 is not online. vastqud
Joined: 10 Sep 2011
Total Posts: 2464
15 May 2016 09:41 AM
ahh, nevermind, it does
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image