Better way for positioning an object with CFrames

I had a problem with CFrame in scripting. I needed an object to be positioned and rotated in a CFrame just like the block below (there are more, but I only focus on one in the situation).

It all works fine just by setting the objects CFrame = block.CFrame, but I need the thing to be placed 0.2 studs above the block.

image

I’ve come up with this:

prop.Position = Vector3.new(mouse.Target:FindFirstChild(PortLocation).Position.X, mouse.Target:FindFirstChild(PortLocation).Position.Y + 0.2, mouse.Target:FindFirstChild(PortLocation).Position.Z)
prop.Orientation = mouse.Target:FindFirstChild(PortLocation).Orientation

But it’s long and looks horrible, so I just want to know if there’s a better way of doing that with CFrames instead of positions and orientations.

prop.CFrame = mouse.Target:FindFirstChild('PortLocation').CFrame+Vector3.new(0, .2, 0)

1 Like

You can use either absentdenik’s answer or this:

prop.CFrame = mouse.Target:FindFirstChild(PortLocation).CFrame*CFrame.new(0,0.2,0)

the only difference being mine does it relative to the parts position and his does it relative to the world.

ALSO wrong category! belongs in #help-and-feedback:scripting-support.

The code was correct just the 0.2 had to be placed in the Z axis, not the Y.

To add, the topic is in the right category because my solution did work, it just wasn’t optimal. :happy1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.