Vector between two Attachment

  1. What do you want to achieve?
    I want to set one Attachment to look at the another one

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

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

		local ac = Instance.new("Attachment", coin)
		local ab = Instance.new("Attachment", coin)

		ac.Position = pos
		ac.Name = "APet"..v.Name
		
		ab.Position = beamPos
		ab.Name = "ABeam"..v.Name
		
		local PetCenter = v.Body.center
		v.Body.Beam.Attachment0 = ab
		v.Body.Beam.Attachment1 = PetCenter

		v.AlignPosition.Attachment1 = ac
		v.AlignOrientation.Attachment0 = PetCenter
		v.AlignOrientation.Attachment1 = ab

I tried a little and noticed that changing WorldOrientation to Attachment changes pet rotation. How to set it up?

1 Like

This is how you would get the CFrame of one attachment ( / part) looking at another

cframe = CFrame.new(a1.CFrame.Position, a2.CFrame.Position) -- a1 looks at a2
1 Like

This constructor overload is now deprecated. Use CFrame.lookAt.

local attachment1: Attachment
local attachment2: Attachment

attachment1.WorldCFrame = CFrame.lookAt(attachment1.WorldPosition, attachment2.WorldPosition)

local ACenter = coin.ACenter
for i, v in pairs(equippedPets) do

	local ac = Instance.new("Attachment", coin)
	local ab = Instance.new("Attachment", coin)

	ac.Position = pos
	ac.Name = "APet"..v.Name
	
	ab.Position = beamPos
	ab.Name = "ABeam"..v.Name
	
	local PetCenter = v.Body.center
	v.Body.Beam.Attachment0 = ab
	v.Body.Beam.Attachment1 = PetCenter

	v.AlignPosition.Attachment1 = ac
	v.AlignOrientation.Attachment0 = PetCenter
	v.AlignOrientation.Attachment1 = ab
	
	ab.WorldCFrame = CFrame.lookAt(ab.WorldPosition, ACenter.WorldPosition)
	
end

They rotate but not to center of the coins

They seem to rotate 90 degrees away.

Try:

* CFrame.Angles(0, 90, 0)

or:

* CFrame.Angles(0, -90, 0)