PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Rotating a Part Towards Another Part

Rotating a Part Towards Another Part

Jun 29 2018, 4:51 PM PST

Problem

You want to rotate a part toward another part.

Solution

Use the second CFrame argument to rotate in that direction.

local part = Instance.new('Part')
part.Parent = Workspace
part.Anchored = true
part.CFrame = CFrame.new(Vector3.new(0, 0, 0), Workspace.pointAtPart.Position)

Discussion

We’re basically setting part.CFrame to a new CFrame which is at the position of (0, 0, 0), and is rotated at the part pointAtPart. We use pointAtPart.Position because we want to point at a Vector3 value which is returned by the Position property or CFrame.p.

Tags:
  • cframe
  • vector3
  • movement
  • animation