Okay, you may be on to something here, but I want this to work with whatever surface based on a raycast using your mouse. So for example, if we the raycast normal is (1,0,0), but the part is rotated (0,0,90), then if you got the area using the part’s upvector and lookvector, you would get the area of the surface currently facing top, since the part is rotated (0,0,90).
Adding on, by area I meant like Vector2. I read this other post (the only one that asks about this other than me) but it gives a very inconcise answer and I’m not sure if their solution was right, because the OP never gave any follow up which is just straight up lame
How will we discover the up and right vectors relative to the surface normal? That’s the only information we have, so what if the part looks like this?
Just so you guys know this is what I mean by discovering the up and right vectors
Without up and right vectors and only the look vector, it’s impossible to determine the size of the area. I need someone with incredibly advanced knowledge of CFrames, Vectors, Geometry, and Roblox… hint hint… Egomoose
I like how every other question this devforum gets answers within like 3 seconds and I have to wait hours and days and even weeks for any sort of remotely close answer
I just found this post from a little bit ago that seems very simular to what you are asking, perhaps you should look some more because googling “roblox how to get area from surface” came up with many results.
That is literally the post I mentioned twice in this thread and if you haven’t realised I posted there three times already
And yes I did google that term along with several other variations and the post you linked is the only post mentioning this, all the other posts on google are irrelevant. If I’m asking this question on devforum that usually means I’ve already googled things.
I just read through again and still don’t see it mentioned anywhere here, I recall you saying there is no posts about this so… idk anything about this topic but you were saying you had no luck so I thought I’d search around
Area of a square: Width times Length. Area of a cube: Width times Length times Depth. Simple math.
I read this other post (the only one that asks about this other than me) but it gives a very inconcise answer and I’m not sure if their solution was right, because the OP never gave any follow up which is just straight up lame
@NullSypher
I’m in high school. You think I wouldn’t know how to calculate the area of a square? I’m trying to find the area of any surface of any part no matter its rotation or size or position.
Take a moment to read what little I have wrote in this thread and maybe you can get a better idea of what I want to achieve.
@SatrapRezaPahlavi
Anyways I have a theory
Given that a part’s CFrame has an UpVector, LookVector and RightVector, you can compare the angle between those vectors and the normal vector of a raycast (ray.Normal)
So, steps:
- Create a table mapping out the values and the results we need
-- assuming you did raycast above this code --
if (hitNormal) then
local dotY = hitNormal:Dot(Vector3.new(0,1,0))
local dotX = hitNormal:Dot(Vector3.new(1,0,0))
local dotZ = hitNormal:Dot(Vector3.new(0,0,1))
if (math.abs(dotY) >= 0.9) then
if (dotY < 0) then
surface = Enum.NormalId.Bottom
else
surface = Enum.NormalId.Top
end
elseif (math.abs(dotX) >= 0.9) then
if (dotX < 0) then
surface = Enum.NormalId.Left
else
surface = Enum.NormalId.Right
end
else
if (dotZ < 0) then
surface = Enum.NormalId.Front
else
surface = Enum.NormalId.Back
end
end
end
Oh nevermind about that CFrame theory, I found this on another DevForum post. lol
So first work done. Now we map up the formula to calculate area for each side.
local s = part.Size
local sideToAreaMapping = {
[Enum.NormalId.Top] = s.X*s.Z,
[Enum.NormalId.Bottom] = s.X*s.Z,
[Enum.NormalId.Left] = s...
Gah I don’t remember which face uses which axis but
left area = right area
front area = back area
So to get the final area
local areaOfSideAtNormal = sideToAreaMapping[surface]
This is only accurate for rectangle and squares – You would need different sideToAreaMapping for different shapes
I’ve been reading this thread for the past hour, sorry that I skimmed over you claiming someone just dropped a post randomly when they marked their solution as the answer, which is what you are supposed to do? Maybe you really should touch some grass
There has to be a more elegant solution than just this. I already have the function to find which Enum the face of the normal is.
Okay, good luck
If I were you I’d stick with what works but then again, I’m not the one facing the problem…
What you gave is a hacky solution which uses manmade tables. I want this to be done completely with only mathematical equations. I have to run three if statements each inside of three if statements, which is sad and bad.
Tell me. Can you read this code?
I sure can’t
It’s completely painful to use manmade arbtirary sets as identifiers for surface size. Yes, it “gets the job done”, but I’ve been taking 2 hours to still make the if statements and it’s hurting my brain
P A I N
(If you don’t know what is happening, if I click anywhere other than the line I’m working on it resets my scrollbar)
This only works for cubes.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local ref = {
[Enum.NormalId.Left] = Vector3.new(1, 1, 0),
[Enum.NormalId.Right] = Vector3.new(1, 1, 0),
[Enum.NormalId.Bottom] = Vector3.new(1, 0, 1),
[Enum.NormalId.Top] = Vector3.new(1, 0, 1),
[Enum.NormalId.Back] = Vector3.new(0, 1, 1),
[Enum.NormalId.Front] = Vector3.new(0, 1, 1)
}
while wait(1) do
local target = mouse.Target
if target then
local size = mouse.Target.Size * ref[mouse.TargetSurface]
print(size)
local sX = size.X == 0 and 1 or size.X
local sY = size.Y == 0 and 1 or size.Y
local sZ = size.Z == 0 and 1 or size.Z
local surfaceArea = sX * sY * sZ
print(surfaceArea)
end
end
If you want to do one for every part then that’s impossible, because MeshParts exist. I’m pretty sure that there’s no current possible way to calculate their surface areas.