Alright, so my problem is pretty basic. I want to make a part look away from a certain position using CFrame.lookAt on one line but I’ve forgotten how to and I can’t find any material covering it. So far the code I’m using is below.
local OriginalPosition = Part2.Position
Part2.CFrame = CFrame.lookAt(Part1.Position,Part2.Position)
Part2.Position = OriginalPosition
As you can see, that’s three lines of code and also setting the properties of the part twice instead of once. I’m pretty sure I remember being able to create a CFrame that looked away from a position instead of towards it without having to reset the position after setting the CFrame. If there is a way please let me know!
Or you could build the matrix yourself (didn’t test this):
local back = Part1.Position - Part2.Position
local right = Vector3.new(0, -1, 0):Cross(back)
local up = back:Cross(right)
Part2.CFrame = CFrame.fromMatrix(Part2.Position, right, up, back)
This function replaces the CFrame.new(Vector3, Vector3) constructor (see above) which accomplished a similar task. This function allows you to specify the up Vector, using the same default as the old constructor.
Alright, so my question has already been answered, but I want to correct you that they are not the same. CFrame.lookAt is a new function that should be used in new works and is meant as a better replacement for CFrame.new with an additional parameter. The additional parameter for CFrame.new only remains for backwards compatability.