Help with CFrames

can someone help me with CFrames, it works but I think it can be more simple (especially the +position part):

local partA = script.Parent
local partB = partA:Clone()
partB:ClearAllChildren()

local offset = CFrame.new(0,partA.Size.Y/2, 0)
local angle = CFrame.Angles(math.rad(45),math.rad(45),math.rad(45))
local targetCFrame = partA.CFrame * angle * offset

partB.CFrame = targetCFrame
partB.Position +=  offset.Position
partB.Parent = workspace
1 Like

the only thing i can think of is to add offset.Position to targetCFrame instead of doing it separately, which would reduce a line of code

1 Like

i updated my code:

~local partA = script.Parent
local partB = partA:Clone()
partB:ClearAllChildren()

local offset = CFrame.new(0,partA.Size.Y, 0)
local angle = CFrame.Angles(math.rad(45),math.rad(45),math.rad(45))
local targetCFrame = partA.CFrame * angle * offset
local thing = partA.CFrame * offset * angle * partA.CFrame:ToObjectSpace(partB.CFrame)

partB.CFrame = thing
partB.Parent = workspace

ok so I was kinda unclear but I have this problem when rotatating:


without rotating:

I agree with you, @WeeklyShoe. Just reduce your lines of code. For example, you can write:
partB.CFrame = CFrame.new(0,partA.Size.Y/2, 0)
Instead of that

1 Like

That sadly won’t work with angles, but thanks anyways

I will test that and reply later…

1 Like
local partB = script.Parent:Clone() partB:ClearAllChildren()
partB.CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(45), 
	math.rad(45), math.rad(45)) * CFrame.new(0, script.Parent.Size.Y/2, 0)
partB.Parent = workspace
1 Like


Thank you, but it still isn’t perfect because it doesn’t sit on top. Any ideas on how to fix that?
like this:

Well, I can guess.. I need to work with things to be sure.

local part = script.Parent:Clone() part:ClearAllChildren()
local angle = CFrame.Angles(math.rad(45), math.rad(45), math.rad(45))
part.CFrame = script.Parent.CFrame * angle +
	angle:VectorToWorldSpace(Vector3.new(0, script.Parent.Size.Y/2, 0))
part.Parent = workspace


It’s not perfect, but it sure is a step in the right direction, thank you for helping and good luck with your work

This is what happens to me too.. lol, keep trying you’ll get it.
Let’s see here.. Trying a different approach..

local part = script.Parent:Clone() part:ClearAllChildren()
local angle = CFrame.Angles(math.rad(45), math.rad(45), math.rad(45))
part.CFrame = script.Parent.CFrame * angle +
	script.Parent.CFrame.UpVector * (script.Parent.Size.Y/2)
part.Parent = workspace
1 Like