You can use lookat with pivoting if you do some offsetting.
Now, I’m assuming from your post you want to pivot and not acting like a point is the center.
Now, bear in mind I haven’t tested the following as much as I should have, so if there is a mistake in my logic, please call out.
local function pivoting_look_at(from, to, pivot_offset)
--[[
Takes arguments:
CFrame (object to create CFrame from),
Vector3 (Point that the new CFrame will look at),
Vector3 (The pivot point in relation to from.)
Returns: CFrame that is looking at the given point having pivoted around an offset.
--]]
assert(typeof(from)=="CFrame", "'pivoting_look_at': Invalid input for 'from'. It is a " .. typeof(from) .. ". Should be a CFrame")
assert(typeof(to)=="Vector3", "'pivoting_look_at': Invalid input for 'to'. It is a " .. typeof(to) .. ". Should be a Vector3.")
assert(typeof(pivot_offset)=="Vector3", "'pivoting_look_at': Invalid input for 'pivot_offset', It is a " .. typeof(pivot_offset) .. ". should be a Vector3")
local offsetfrom = from:ToWorldSpace(CFrame.new(pivot_offset))
--[[Use the lookat CFrame creation with the offset position looking at
the "Worldly" similar offset to-position.
Effectively 'pivoting around a point']]--
local ret = CFrame.new(offsetfrom.Position, to + offsetfrom.Position - from.Position)
-- Return the pivoted center and not the pivoted pivot point.
ret = ret:ToWorldSpace(CFrame.new(-pivot_offset))
return ret
end
Using your yellowblock example, to achieve what you did you would use