Parts offseted? Why?

So basically I am creating a script that surrounds the main part with other parts, only problem is the other parts are off to the side by a little:

OG part is a part as said by the name, SpaceApart is 5. and Rotate is 12.

	for t = 0, amount, 1 do
		-- set the po2
		local Part = Createpart()
		local weld = Instance.new('Weld')
		weld.Parent = originPart
		weld.Part0 = originPart
		weld.Part1 = Part


		-- set the position and stuff
		local x = math.cos(math.rad(t) * (rotate / (t / t)))
		local y = math.sin(math.rad(t) * (rotate / (t / t)))
		


		weld.C1 = ogPart.CFrame * CFrame.new(x * spaceApart, y * spaceApart, 0)
end

Not sure why this is happening at all but here are my assumptions:

I tried doing this without X and Y. Its still offseted, meaning that even at the value being 0 its offseted. So its got nothing to do with the X and Y values.

Tell me what yalls think cause I have no idea what is going on

I’m not sure I understand what you mean by this, but are you attempting to do this?

Another example, but without additional rotations

Yes basically this, except Im not trying to make the other parts keep following around the main part.

Don’t worry that was just for demonstration purposes

I believe the problem is that you are multiplying the position rather than adding them.

-- Old (from your example)
weld.C1 = ogPart.CFrame * CFrame.new(x * spaceApart, y * spaceApart, 0)
-- New
weld.C1 = ogPart.CFrame + CFrame.new(x * spaceApart, y * spaceApart, 0)

However, if you run into problems, just view my code or ask me a question; I don’t mind.

local amount = 20
local radius = 5
local subject = workspace.Part
for i = 0, amount do
	local part = Instance.new("Part", subject)
	part.Anchored = true
	part.Size = Vector3.new(1, 1, 1)
	part.Transparency = 0.5

	local angle = (math.pi * 2 / amount) * i

	-- Calculate the rotation matrix based on the subject's rotation
	local rotationMatrix = CFrame.Angles(math.rad(subject.Rotation.x), math.rad(subject.Rotation.y), math.rad(subject.Rotation.z))

	-- Calculate the position relative to the subject's rotation
	local offset = Vector3.new(math.sin(angle) * radius, 0, math.cos(angle) * radius)

	-- Apply the rotation matrix to the offset
	local rotatedOffset = rotationMatrix:pointToWorldSpace(offset)

	-- Set the part's position relative to the subject's position and rotation
	part.Position = subject.Position + rotatedOffset
end
1 Like

this gives the error

invalid argument #2 (Vector3 expected, got CFrame)

Please correct me if I’m incorrect, but I forgot to note that apparently you can’t add Cframes together. Change the Cframes to only contain their positional data (Vector3s) to resolve this.

-- Revision 1
weld.C1 = ogPart.CFrame.Position + CFrame.new(x * spaceApart, y * spaceApart, 0).Position
1 Like

See I need to give it a CFrame this gives it a vector3.
As shown:

Unable to assign property C1. CoordinateFrame expected, got Vector3

Sorry for the mistake. Of course, you could simply wrap the vectors in a CFrame.

-- Revision 2
weld.C1 = CFrame.new(ogPart.CFrame.Position + CFrame.new(x * spaceApart, y * spaceApart, 0).Position)

Heck why didnt I think about that. Whoops lol.

Nope now its more offseted:

Hmm. Could you please provide any further information about this script? Right now, I’m not really sure what “ogPart” implies. If at the very least you could provide the variable properties or the entire source. that would be extremely useful.

Sure here they are:
This is where I create the ogPart:

local ogPart = Createpart()
ogPart.CFrame = po * CFrame.new(0,0,-Range)
ogPart.Anchored = true
ogPart.CanTouch = false
ogPart.CanCollide = false
ogPart.CanQuery = false
ogPart.Parent = workspace

Now the PO value is a CFrame of a part in the workspace which is:

3, 27.4999962, 18, 1, 0, 0, 0, 0.587785244, 0.809017062, 0, -0.809017062, 0.587785244

and range is just a number, which is:

15

Also this is the create part function if you want it:

function Createpart()
local part = Instance.new(“Part”)
part.Anchored = false
part.Size = Vector3.new(1,1,1)
part.Parent = workspace
part.Transparency = 0.5
return part
end

By the way, why not just adjust the position instead of utilizing a weld if you don’t want the surrounding parts to align with the main part? The issue is presumably with the weld. To clarify this problem, we are adding twice the subject position to the weld part, which is already moving the components to the part you specified. This can probably be taken out and function.

-- Revision 3
weld.C1 =  CFrame.new(x * spaceApart, y * spaceApart, 0)

This is only a guess, and its success is not guaranteed.

My mistake: I forgot to remove the position component in the CFrame.

1 Like

Oh yeah thatd probably make sense. Ill try it out

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