I am currently working on a building tool, and am facing a problem with placing parts that are something else than just a cube. So I have came up with a possible solution: The game would calculate the height/thickness/length of a part. The problem is, I don’t know how to get these properties with my current script. Let’s say I want to get the height property of a part.
In this image, that is just a regular part, and the height property would be the Size.Y value of a part. However, my building tool utilizes rotation, and when that same part is rotated, the desired height value (dhv for short) would no longer by the Size.Y value and instead will be Z (or X, depending on how the part is rotated).
Now, I don’t know how would I change the desired height/thickness/length value of a part depending on its rotation. Are there any methods for like take the size property of the part depending on the world root and not the root of a part?
You could calculate what the “apparent topSide” is by comparing the face normal with vector3.new(0,1,0)
I am thinking about something like this:
local CF = part.CFrame
local normals = {CF.XVector, CF.YVector, CF.ZVector}
for i, v in ipairs(normals) do
UpAmount = result.normal:Dot(vector3.new(0,1,0))
if UpAmount > 0.4 then
--it is topside
end
end
That might work, but would be quite complicated I believe.
what makes you think so?
I would very much appreciate a bit more context about this tool and how it works, perhaps some examples in-game
Ok, here is the current script Im using. It works just perfectly with cubes, but with other shapes, it is not that awesome, as the parts are partically fazing through others. The script is paranted to the tool, which also holds blockHolo and Block
local ContextActionService = game:GetService("ContextActionService")
local players = game.Players
local player = players.LocalPlayer
local tool = script.Parent
local block = tool.Block
local holo = tool.BlockHolo
local mouse = player:GetMouse()
local connection = mouse.Move:Connect(function() -- Display
local mousePosition = Vector3.new(math.round(mouse.Hit.Position.X), math.round(mouse.Hit.Position.Y), math.round(mouse.Hit.Position.Z))
local target = mouse.Target
local targetSurface = mouse.TargetSurface
if targetSurface == Enum.NormalId.Top then
holo.Position = mousePosition + target.CFrame.UpVector
elseif targetSurface == Enum.NormalId.Bottom then
holo.Position = mousePosition - target.CFrame.UpVector
elseif targetSurface == Enum.NormalId.Front then
holo.Position = mousePosition + target.CFrame.LookVector
elseif targetSurface == Enum.NormalId.Back then
holo.Position = mousePosition - target.CFrame.LookVector
elseif targetSurface == Enum.NormalId.Right then
holo.Position = mousePosition + target.CFrame.RightVector
elseif targetSurface == Enum.NormalId.Left then
holo.Position = mousePosition - target.CFrame.RightVector
end
end)
local function RotateAndPlace(actionName, inputState, inputObject) -- Rotate
if inputObject.KeyCode == Enum.KeyCode.R and inputState == Enum.UserInputState.Begin then
holo.CFrame = holo.CFrame * CFrame.Angles(0, math.rad(90), 0)
elseif inputObject.KeyCode == Enum.KeyCode.T and inputState == Enum.UserInputState.Begin then
holo.CFrame = holo.CFrame * CFrame.Angles(0, 0, math.rad(90))
elseif inputObject.UserInputType == Enum.UserInputType.MouseButton1 and inputState == Enum.UserInputState.Begin then
local clone = holo:Clone()
clone.Transparency = 0
clone.Parent = workspace.PlayerStructures
clone.Name = "Block"
clone.CanCollide = true
clone.Anchored = false
local weld = Instance.new("WeldConstraint")
weld.Parent = clone
weld.Part0 = clone
weld.Part1 = mouse.Target
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction("Rotate and Place", RotateAndPlace, false, Enum.KeyCode.R, Enum.KeyCode.T, Enum.UserInputType.MouseButton1)
holo.Transparency = 0.5
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction("Rotate and Place")
holo.Transparency = 1
end)
wait. all you want to do is place parts, right?
Then you should just use Shapecast
by doing so you will get the exact position where you want to place your object without even doing the math yourself. Just let the computer do it
Isn’t the shapecast is just a cast of a part with the given position as its center?
Shapecast is a raycast but with volume
This might help, thank you, I guess.
And sorry for late reply