I just want to simply create a bullet hole image on a surface gui. I didn’t even think of this problem when I started, but I can’t actually think of how to solve it:
How do I figure out which FACE of the part I hit? I can’t just use Result.Normal, because that is just a direction, not a surface. I want it so if, for example, a part is rotated, and I shoot it’s left side, I can tell it 's the left side of the part, and apply a surface gui appropriately. I don’t know how to get this information out of a normal, though.
Make a small part with a decal on the back, place in on the hit position and make it face towards the normal, i don’t know how to do the last part honestly
This is… what I used to do, and specifically has none of the benefits I’m looking for. Thanks for the input though!
Why do you need a SurfaceGUI specifically, also the SurfaceGUI will worth a bit weirdly with round objects i think + it covers the entire side of the object instead of a small part so you’ll have to resize the part to be exactly where you want it, you can do that with Maths anyways
I want a surface gui for a variety of reasons, mainly being the fact that bullet hole decals may go off the edge. Also, I have no intent to use round objects.
local function getNormalId(normalVector)
for _, normalId in ipairs(Enum.NormalId:GetEnumItems()) do
if Vector3.FromNormalId(normalId) == normalVector then
return normalId
end
end
end
print(getNormalId(Vector3.xAxis)) -- Enum.NormalId.Right
What if my vector3 isnt just (0,1,0) or something like that. If a part was rotated, would the code still work there? I haven’t ran this yet, but it looks like that might be a problem. If I’m wrong, sorry.
Forgot about that sorry.
local function getNormalId(part, worldSpaceNormalVector)
local objectSpaceNormalVector = part.CFrame:VectorToObjectSpace(worldSpaceNormalVector)
for _, normalId in ipairs(Enum.NormalId:GetEnumItems()) do
if Vector3.FromNormalId(normalId) == objectSpaceNormalVector then
return normalId
end
end
end
print(getNormalId(part, RaycastResult.Normal))
I’ll try this out in a moment.
There are rounding errors which prevent it from equalling properly, and no matter what I do, I can’t fix them! I’ve tried a variety of different things, and nothing works.
Ok, nevermind! I Squashed the error and it works now, but the rounding error was a bit… painful to fix
Hi, can you share what your end solution was that you fixed?
Thanks
I just did some… inefficent rounding to say the least. (All the simple methods didn’t work)
local osnv = part.CFrame:VectorToObjectSpace(worldSpaceNormalVector)
local x = 0
local y = 0
local z = 0
if osnv.X > 0.9 or osnv.X < -0.9 then
x = math.round(osnv.X)
end
if osnv.Y > 0.9 or osnv.Y < -0.9 then
y = math.round(osnv.Y)
end
if osnv.Z > 0.9 or osnv.Z < -0.9 then
z = math.round(osnv.Z)
end
osnv = Vector3.new(x,y,z)
To compare two vectors you can use Vector3:FuzzyEq(Vector3)
which basically checks to see if they are close to equal (within .00001 studs default).
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.