Hello DevForum,
So recently I’ve been working on something that can get the surface size of practically any object; however, I ran into an issue with getting the surface center rotated CFrame for rotated objects. I think that I am very close to figuring it out but I’ve been stuck on it for a couple days from working on it on and off. Another mind to help me with this would be very beneficial to save time. Let me provide some context…
Here is a video detailing my current progress:
Here is my code for this example:
local function GetSurfaceInfo(HitNormal, HitInstance)
local Offset = HitInstance.Size.Magnitude * 2
local BackRay = CFrame.new(HitInstance.Position) * CFrame.Angles(HitNormal:ToEulerAnglesXYZ())
local LookDirection = BackRay * CFrame.new(0,0,-Offset)
FaceCenterParams.FilterDescendantsInstances = {HitInstance}
FaceCenterParams.FilterType = Enum.RaycastFilterType.Whitelist
local RayResult = workspace:Raycast(LookDirection.Position, LookDirection.LookVector * -(Offset + 1), FaceCenterParams)
if not RayResult then return end
local SurfaceCenter = CFrame.new(RayResult.Position, RayResult.Position + RayResult.Normal)
local SurfaceSize, SurfaceCFrame, CornerCFrame = GetSurfaceSize(SurfaceCenter, Offset, HitInstance.CFrame)
Part.CFrame = SurfaceCenter --
return SurfaceSize, SurfaceCFrame, CornerCFrame, LookDirection
end
From my hypothesis, I assume that I may be able to get the normal rotation from the object’s ObjectSpace given the HitNormal CFrame. Here is an example of that working:
While this does work, it does not give me the outward lookvector from the given raycast normal.
Here is my code for this example:
local function GetSurfaceInfo(HitNormal, HitInstance)
local Offset = HitInstance.Size.Magnitude * 2
local BackRay = CFrame.new(HitInstance.Position) * CFrame.Angles(HitNormal:ToEulerAnglesXYZ())
local LookDirection = BackRay * CFrame.new(0,0,-Offset)
FaceCenterParams.FilterDescendantsInstances = {HitInstance}
FaceCenterParams.FilterType = Enum.RaycastFilterType.Whitelist
local RayResult = workspace:Raycast(LookDirection.Position, LookDirection.LookVector * -(Offset + 1), FaceCenterParams)
if not RayResult then return end
local HitNormal2 = CFrame.new(RayResult.Position, RayResult.Position + RayResult.Normal)
local ObjectRelativeRotatation = HitInstance.CFrame:ToObjectSpace(HitNormal2)
local SurfaceCenter = HitInstance.CFrame:ToWorldSpace(CFrame.new(ObjectRelativeRotatation.Position))
local SurfaceSize, SurfaceCFrame, CornerCFrame = GetSurfaceSize(SurfaceCenter, Offset, HitInstance.CFrame)
Part.CFrame = SurfaceCenter --
return SurfaceSize, SurfaceCFrame, CornerCFrame, LookDirection
end
If you have any questions please ask, I plan on creating this as an open source once i get this part figured out.
Thanks,
Tave