Part just disappearing when rotating it?

Its jiggling because you have feedback: p2.CFrame involved in the calculation of the new p2.CFrame.
But let me stop you right here because you have a broader issue. This is not the answer you want but its likely to save you a lot of headache:
You’re trying to do a calculation that is fundamentally a vector math problem using trig. You don’t have to jump between domains like this and it will probably just keep getting you into strange math trouble, although it is possible to do. For this specific problem it would be easier to use CFrame.lookAt, but most problems like this can be solved using only methods of CFrame and Vector3 without ever having to go to trig. The reason you should avoid trig is because trig is one dimensional, it states things about the unit circle, all its inputs and outputs are scalars. Any time you have to go back and forth between Vectors and trig, you have to make very precise definitions about “where” you’re measuring angles and often one angle can mean two different things based on some extra information. In your code, it has no way of telling the difference betwen being angled at 45 degrees vs 135 degrees, they both represent the result of taking the smallest angle between two vectors and will both appear to be 45 degrees.

No it doesnt! Please at least check before saying this!

So your saying im not doing anything wrong?

No way of solving a math problem is “wrong” but you’ve definitely chosen a harder way to do it. Its a totally understandable train of logic to get to this code though, and the reasons why its hard aren’t that obvious up front, thats why I wanted to back up and explain why it seems harder than it should be.

Okay then there is a solution so help me find it
image

My bad, I forgot 180 degrees was pi/2, not just pi.

So acos is just a piece of x = cos(y), between (0, pi] on the y axis. But I still really don’t know the use case for that curvy line. I’ll look it up later.
image

This is solving a slightly different problem, it is checking is the angle between the guards view direction and the direction to the hero are lower than some number. In this case it is ok that two different D’ vectors will give the exact same angle for any chosen angle. In your case that isn’t ok because you need to know which direction to rotate, not just by how much.

1 Like

Okay well I’m just lost at what to do now… I wanted to just get the basics down to really understand the fundamentals of linear algebra in game dev

but now i dont know what to do…

This is a really good vector math video I recommend: Vectors & Dot Product • Math for Game Devs [Part 1] - YouTube
There are multiple parts and it’s pretty long but you can skip any sections you already know, and its still much shorter than taking linear algebra + vector calc classes.

This section talks about this exact scenario:

Ill explain.
image
The unit circle is a representation of every possible right triangle scaled down to where it’s hypotenuse is equal to one. You’ve probably heard sin(x), before, right? that’s just equivalent to the height of that triangle, or the y. cos(x) is equivalent to width of the triangle, or the x.

ARCcos is equivalent to the inverse of cos. cos^-1, it’s not actually cos^-1, it’s just a way of saying it. So if you plugged in 1 into arccos(), since cos(0 degress) is 1, because a right triangle with an angle of zero degrees would have the width of one, then the arccos of 1 would be 0 degrees, the opposite.
image

Here’s an even better video:

He explains everything as if he knows exactly the way you should learn it, and he has nice animations. Watch him.

Thanks for telling me, now I know that I will never understand this… so nevermind.