Sorry if the title sounds weird. I wan’t to make so that I can get every vector3 point of a part so I can place attachments in every point. Kinda like this post.
Is this possible? All answers are appreciated.
Sorry if the title sounds weird. I wan’t to make so that I can get every vector3 point of a part so I can place attachments in every point. Kinda like this post.
Is this possible? All answers are appreciated.
If you mean every signle point within a part, then you’re gonna have a bad time doing anything with it, because there’s an infinite amount of points in a shape. the amount of points you’re going to get is dependant on how many you’ll accept per stud^3.
If you mean every corner, then you can just take the part’s position, and add or subtract half of it’s size to get the position of each corner.
Can you show me how to get every corner then?
local Part = script.Parent
local PartPosition = script.Parent.Position
local PartSize = script.Parent.Size
------------Corners----------------
local TopRightFrontCorner = .5*PartSize
local TopLeftFrontCorner = .5*Vector3.new(PartSize.X,PartSize.Y,-PartSize.Z)
local BottomRightFrontCorner = .5*Vector3.new(PartSize.X,-PartSize.Y,PartSize.Z)
local BottomLeftFrontCorner = .5*Vector3.new(PartSize.X,PartSize.Y,-PartSize.Z)
------------Back-------------------
local TopRightBackCorner = .5*Vector3.new(-PartSize.X,PartSize.Y,PartSize.Z)
local TopLeftBackCorner = .5*Vector3.new(-PartSize.X,PartSize.Y,-PartSize.Z)
local BottomRightBackCorner = .5*Vector3.new(-PartSize.X,-PartSize.Y,PartSize.Z)
local BottomLeftBackCorner = .5*-PartSize
It really isn’t as complicated as you probably think. also, what are you trieng to make?
I was gonna place attachments inside of a Sphere. The attachments serve as the hitbox. Its part of this: Raycast Hitbox 4.01: For all your melee needs!
I’ll test this out right now and see if it works.
There are a lot of ways to check for collisions, but raycasting towards where the player is aiming, or where the sword is heading at a given moment (so it’s more realistic) is better than checking the full volume of one or multiple parts.
This will not work for rotated parts. Instead consider something like this, which will produce the rotated offsets in object space for corners.
function GetCorners(part)
local cf = part.CFrame:ToObjectSpace(part.CFrame);
local size = part.Size;
return {
cf * CFrame.new(-size.X / 2, -size.Y / 2, -size.Z / 2),
cf * CFrame.new(-size.X / 2, size.Y / 2, -size.Z / 2),
cf * CFrame.new(-size.X / 2, size.Y / 2, size.Z / 2),
cf * CFrame.new(-size.X / 2, -size.Y / 2, size.Z / 2),
cf * CFrame.new(size.X / 2, -size.Y / 2, -size.Z / 2),
cf * CFrame.new(size.X / 2, size.Y / 2, -size.Z / 2),
cf * CFrame.new(size.X / 2, size.Y / 2, size.Z / 2),
cf * CFrame.new(size.X / 2, -size.Y / 2, size.Z / 2)
}
end
Ok, i’ll see if that works.
I tried this and it didn’t work, what did I do wrong?
coroutine.resume(coroutine.create(function()
for _ = 1, 25 do
wait()
b.Transparency = b.Transparency + 0.04
b.Size = b.Size + Vector3.new(0.5, 0.5, 0.5)
for i, v in pairs(b:GetChildren()) do
wait()
--b is the Part
--v is the Attachments inside of the part
function GetCorners(part)
local size = b.Size
local cf = v.CFrame:ToObjectSpace(v.CFrame)
return {
cf * CFrame.new(-size.X / 2, -size.Y / 2, -size.Z / 2),
cf * CFrame.new(-size.X / 2, size.Y / 2, -size.Z / 2),
cf * CFrame.new(-size.X / 2, size.Y / 2, size.Z / 2),
cf * CFrame.new(-size.X / 2, -size.Y / 2, size.Z / 2),
cf * CFrame.new(size.X / 2, -size.Y / 2, -size.Z / 2),
cf * CFrame.new(size.X / 2, size.Y / 2, -size.Z / 2),
cf * CFrame.new(size.X / 2, size.Y / 2, size.Z / 2),
cf * CFrame.new(size.X / 2, -size.Y / 2, size.Z / 2)
}
end
end
end
end))
Not sure what you are trying to do with the coroutine or the wait, but I quickly wrote this for creating and positioning the attachments correctly.
local part = workspace.Part;
function GetCorners(part)
local cf = part.CFrame:ToObjectSpace(part.CFrame);
local size = part.Size;
return {
cf * CFrame.new(-size.X / 2, -size.Y / 2, -size.Z / 2),
cf * CFrame.new(-size.X / 2, size.Y / 2, -size.Z / 2),
cf * CFrame.new(-size.X / 2, size.Y / 2, size.Z / 2),
cf * CFrame.new(-size.X / 2, -size.Y / 2, size.Z / 2),
cf * CFrame.new(size.X / 2, -size.Y / 2, -size.Z / 2),
cf * CFrame.new(size.X / 2, size.Y / 2, -size.Z / 2),
cf * CFrame.new(size.X / 2, size.Y / 2, size.Z / 2),
cf * CFrame.new(size.X / 2, -size.Y / 2, size.Z / 2)
}
end
for i = 1, 8 do
local attachment = Instance.new("Attachment");
attachment.Visible = true;
attachment.Name = i;
attachment.Parent = part;
end
function OnChanged()
local corners = GetCorners(part);
for i,v in ipairs(corners) do
part:WaitForChild(i).CFrame = v;
end
end
OnChanged();
part.Changed:Connect(OnChanged);
I’ll try it out right now.
It works as intended, thank you!