CFrame.lookAt() no working as intended

Exactly as the title says. Here’s the script:

local Blue = script.Parent.Blue
local Red = script.Parent.Red

spawn(function()
	while wait(1) do
		Red.CFrame = Red.CFrame*CFrame.Angles(0,math.rad(90),0)
		Blue.CFrame = CFrame.lookAt(Blue.Position,Red.CFrame.LookVector)
	end
end)

Here’s a video:
https://gyazo.com/c3e559678394452130041fdfc23ba434

1 Like

Try this: `local Blue = script.Parent.Blue
local Red = script.Parent.Red

spawn(function()
while wait(1) do
Red.CFrame = Red.CFrame*CFrame.Angles(0,math.rad(90),0)
Blue.CFrame = CFrame.lookAt(Blue.Position,Red.Position + Red.CFrame.LookVector)
end
end)` (Sorry if any issues with the post, I haven’t really posted properly before.

2 Likes

Please describe what you want Blue to do. Where or what is Blue supposed to “lookAt”?

1 Like

hmmm no, this still doesn’t work, sadly, I haven’t touched Roblox in a while, so I don’t know what they have changed with CFrame, now even when you use CFrame.new() it doesn’t work either, im confused.
Here’s your exact script pasted into studio:
https://gyazo.com/158fbf6109af636934b111728b21d0aa

1 Like

Hi there,
your problem seems to be due to a bit of confusion regarding what CFrame.lookAt does.
First of all, CFrame.lookAt is no longer necessary, as a rather old update to Roblox added its functionality as a normal constructor for CFrames, meaning that doing CFrame.new(Pos1,Pos2) is the same as doing CFrame.lookAt(Pos1,Pos2).
The actual problem here is that CFrame.lookAt doesn’t work the way you think it does.
It takes 2 arguments, both of type Vector3, the first argument is the position of the CFrame, whilst the second argument is the position the CFrame to point to (i.e. “look at”). What you are doing here is constructing a new CFrame which points to a unit vector (LookVector), this means it will always (roughly) point towards the center of the world. In actuality what you want to do is:

CFrame.new(Blue.Position,Red.Position)

This will construct a new CFrame at Blue’s position, and said CFrame will look towards Red’s position.

Hope this helps!

1 Like

Hello, I am not 100% sure If this helps but I think that CFrame.lookAt creates a CFrame that points from one position to another. However, in your script, you are using Red.CFrame.LookVector as I can see, which is a vector that represents the forward direction of the Red part, not its position.

You should change Red.CFrame.LookVector to Red.Position so that Blue looks at Red’s position

Blue.CFrame = CFrame.lookAt(Blue.Position, Red.Position)

local Blue = script.Parent.Blue
local Red = script.Parent.Red

spawn(function()
    while wait(1) do
        Red.CFrame = Red.CFrame * CFrame.Angles(0, math.rad(90), 0)
        Blue.CFrame = CFrame.lookAt(Blue.Position, Red.Position)
    end
end)

1 Like

Sorry for not stating myself clear, but I DO, wanna make it look at the same direction as the part “Red”, which is why I inserted Red.CFrame.LookVector, sorry for the confusion.

local Blue = script.Parent.Blue
local Red = script.Parent.Red

spawn(function()
    while wait(1) do
        Red.CFrame = Red.CFrame * CFrame.Angles(0, math.rad(90), 0)
        Blue.CFrame = CFrame.lookAt(Blue.Position, (Red.CFrame+Red.CFrame.LookVector*Vector3.new(1000, 0, 1000)).Position)
    end
end)
1 Like

Ah, then the solution is quite simple.
As I mentioned in my reply, the second argument is the position the CFrame will point to.
If you want to make the blue part point in the same direction as the red part, you simply do this:

Blue.CFrame = CFrame.new(Blue.Position, Blue.Position + Red.CFrame.LookVector)

Hope this helps!

3 Likes

this also works! thx alot for helping out :grinning:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.