Hi. I made some code that, based on the rotation and a given position, always places itself on top to prevent my piece from “falling” relative to its given position.
Code:
local function placeAbove(position, object)
local objectCFrame = object.CFrame
local objectSize = object.Size
local rightOffset = objectCFrame.RightVector * (objectSize.X / 2)
local upOffset = objectCFrame.UpVector * (objectSize.Y /2)
local forwardOffset = objectCFrame.LookVector * (objectSize.Z / 2)
local offset = Vector3.new(
math.abs(rightOffset.X) + math.abs(forwardOffset.X) + math.abs(upOffset.X),
math.abs(rightOffset.Y) + math.abs(forwardOffset.Y) + math.abs(upOffset.Y),
math.abs(rightOffset.Z) + math.abs(forwardOffset.Z) + math.abs(upOffset.Z)
)
local newPosition = position + offset
object.CFrame = CFrame.new(newPosition) * objectCFrame.Rotation
end
local raypos = workspace:Raycast(
game.Workspace.Camera.CFrame.Position,
game.Workspace.Camera.CFrame.LookVector * 1000
)
if raypos then
placeAbove(raypos.Position, workspace.EjemploPieza)
local p = Instance.new("Part",workspace)
p.Position = raypos.Position
p.Size = Vector3.new(.2,.2,.2)
p.Anchored = true
p.CanCollide = false
p.Transparency = 0.5
p.Shape = Enum.PartType.Ball
p.Color = Color3.new(1,0,0)
end
Resultado:



As you can see, it moves to the top corner, but I have no idea why. What I’m looking for is:

Keeping in mind that the rotation won’t always be perfect, so just halving the Y-axis size won’t work for me.
SORRY FOR MY ENGLUSH