Hello guys. I’m trying to implement rocks and ores in my game. And to do so, I have chosen to work with dodecahedrons. It’s 3D figure which consists out of 12 pentagons. But I have got some problems with it:
Ore pieces should cover dodecahedrone’s surface, but they do this not perfectly - they may float in air sometimes.
Screenshot of ores:
As you can see, some bits are deeper into the rock, some are more open. Code should place them on surface equally, which it fails for now. Sadly, after day spent, I was unable to find mistake myself, so I’m asking for your guys help.
local Angle = math.random(0, 360) * math.pi/180
local Depth = (20 - math.random(0, 400)^0.5)/20
--local Side = 0.6178910239805036
local Height = 0.7824446016137838
local Angle2 = math.pi/5 - math.abs(Angle % (math.pi/2.5) - math.pi/5)
local DepthMod = Height / math.cos(Angle2)
local X = math.cos(Angle) * Depth * DepthMod
local Y = math.sin(Angle) * Depth * DepthMod
local DotOnSurface = Vector3.new(X, 0, Y)
--Code above correctly makes point on pentagon. But IDK on which scale...
DotOnSurface *= 0.567917 / 1.56098 --tried to fix with blender measurement tool. I think I have failed.
local DodecahedronRadius = 0.405
local Side = math.random(1, 12)
--here it should to try select 1 surface and put ore dot relative to that surface.
--code fails with this too. (most likely)
if Side == 1 then
return CFrame.new(0, -DodecahedronRadius, 0) * DotOnSurface
elseif Side == 12 then
return CFrame.new(0, DodecahedronRadius, 0) * DotOnSurface
elseif Side <= 6 then
return CFrame.fromEulerAngles(-math.pi/2.5, (Side - 1) * math.pi/2.5, 0, Enum.RotationOrder.YXZ) * CFrame.new(0, DodecahedronRadius, 0) * DotOnSurface
else
return CFrame.fromEulerAngles(-math.pi/2.5, (Side - 6.5) * math.pi/2.5, 0, Enum.RotationOrder.YXZ) * CFrame.new(0, -DodecahedronRadius, 0) * DotOnSurface
end
--[==[
Some math.pi conversions:
math.pi = 180 degrees
math.pi/180 = used to convert degrees to radians
math.pi/5 = 72 degrees
math.pi/2.5 = 36 degrees
--]==]