Positionate Attachment

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

A Creator Of Hinge Constraints

  1. What is the issue? Include screenshots / videos if possible!

i’m try to set the cframe but positionates far of the expected position

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

yes i’m search

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

this is my code

					local a1 = lastpart:FindFirstChild("Attachment") or Instance.new("Attachment")
					local a2 = v:FindFirstChild("Attachment") or Instance.new("Attachment")
					
					a1.Parent = lastpart
					a2.Parent = v
					
					local c1 = lastpart.CFrame:Inverse()*v.CFrame
					local c2 = v.CFrame:Inverse()*lastpart.CFrame
					local p1 = lastpart.Position
					local p2 = v.Position
					
					local Distance = (v.Position-lastpart.Position).Magnitude
					local s1 = v.Size.Magnitude
					local s2 = lastpart.Size.Magnitude
					
					a1.CFrame = CFrame.new(p1,p2)
					a2.CFrame = CFrame.new(p2,p1)
  • Note: the extra variables is for before tryes for positionate correctly

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The Attachment locations are relative. To make them not relative simple add a World Infront of whenever you are setting Position or CFrame
Attachment.WorldCFrame = CFrame

a1.WorldCFrame = CFrame.new(p1,p2)
a2.WorldCFrame = CFrame.new(p2,p1)
1 Like

this is the expected attach

but this is the result

u know some mathematic to make how the expected?

Hmm. Yes, However it might be easier to raycast.

Do you want the attachments to always be on the closest side regardless of rotation?

If so, then raycast would be easier.

If not you just have to subtract the Size.Z from both parts / 2 (If both parts are looking at each other.)

i’m not like the raycast to this things exists it’s other option?
how the lerp

Okay then. Then all you have to do is subtract the size of. The part from where the Position is at.

Both parts have to be looking at each other for this to work.

(To simply I used lookvector)

local Ap1 = Part.CFrame.LookVector * (Part.Size.Z / 2) 
a1.WorldCFrame = CFrame.new(p1 + Ap1,p2)