CFrame.lookAt not rotating part to look at point

  1. What do you want to achieve?
    I want to rotate a part to face a point.
  2. What is the issue? Include screenshots / videos if possible!
    At certain locations, the part does not appear to rotate properly.

2bd841da9bcd4e4c14365fa812899ae1ca3c1b77

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

I have tried using CFrame.new(vec1, vec2) where vec1 and vec2 are the start and end points for the desired lookVector. I have also tried CFrame.lookAt(vec1, vec2), which was also unsuccessful. I use :ToEulerAnglesXYZ() to get the x, y, and z values of the look CFrame since I am only interested in changing the Y rotation of the part.

– This is an example Lua code block

local look = CFrame.new(vec1, vec2)
local x, y, z = look:ToEulerAnglesXYZ()

–part.Rotation = Vector3.new(part.Rotation.X, math.deg(y), part.Rotation.Z) if part.Position.X > circle.CFrame.Position.X then
part.Rotation = Vector3.new(part.Rotation.X, math.deg(y) + part.Rotation.Y, part.Rotation.Z)
else
part.Rotation = Vector3.new(part.Rotation.X, part.Rotation.Y - math.deg(y), part.Rotation.Z)
end

– This is an example Lua code block

local look = CFrame.new(vec1, vec2)
local x, y, z = look:ToEulerAnglesXYZ()

part.Rotation = Vector3.new(part.Rotation.X, math.deg(y), part.Rotation.Z)

If needed, the full code for creating each green segment is below:

– This is an example Lua code block

while num < #ptList do

local vec1 = ptList[num]
local vec2 = ptList[num+1]
local pos = Vector3.new(((vec2.X - vec1.X)/2) + vec1.X, circle.CFrame.Position.Y, ((vec2.Z - vec1.Z)/2) + vec1.Z)
local dist = math.sqrt(math.pow(vec2.X - vec1.X, 2) + math.pow(vec2.Z - vec1.Z, 2))
local part = Instance.new(“Part”)
part.Anchored = true
part.Size = Vector3.new(0.1,0.1,dist)
part.Name = “part”
part.Parent = game.Workspace.Cracks
part.BrickColor = BrickColor.new(“Lime green”)
part.Position = pos
local look = CFrame.new(vec1, vec2)
local x, y, z = look:ToEulerAnglesXYZ()

–part.Rotation = Vector3.new(part.Rotation.X, math.deg(y), part.Rotation.Z)

if part.Position.X > circle.CFrame.Position.X then
part.Rotation = Vector3.new(part.Rotation.X, math.deg(y) + part.Rotation.Y, part.Rotation.Z)
else
part.Rotation = Vector3.new(part.Rotation.X, part.Rotation.Y - math.deg(y), part.Rotation.Z)
end

table.insert(uList, part)
num += 1

end

I would like to note that the issue does not always occur in the same spot. On other tests, the issue does not occur on the “left” side of the shape, only on the “right”, but has never occurred on the “top” or “bottom”. If somebody has asked this question before me, I have been unable to find it.

1 Like

What do you mean by start and end points for vec1 and vec2?
If this isn’t what you have already, vec1 should be the part’s position, and vec2 should be where the part is facing.

vec1 and vec2 are vector3’s containing the positions of points that could be used to create parts