4e6a4b09-100e-4280-bf88-46b102cf6afb

3ad90192-f6c7-44e8-b666-2aa8761c6a22

Don’t use the 2nd argument of Instance.new, it does not work very well performance wise.

1 Like

026447e6-e376-4722-b88f-e080e737e3ba

what do you mean when the camera is past a certain angle? What is that certain angle, is it constant? How is that angle meant to be measured?

c7a06f2b-71a7-4014-aa80-51d1db337f15

The 2nd argument defines a parent to Instance.new. Benchmark data shows that using this argument will cause major performance drops since the parent is already assigned. The better solution is to parent it after setting the properties of the instance.

1 Like

But they don’t assign any other properties. This is a valid use of the second parameter.

To get the similarity between angles we use Vector3’s Dot function. This blog post has a section on dot products and shows an example using it for quick line of sight checks (how similar the guard’s look direction is to where the player is).

Dot will return 1 if the two vectors are pointing in the same direction, -1 if they are pointing in exact opposite directions, 0 if one is pointing perpendicular to the other (such as LookVector:Dot(RightVector)). The return will result in many in-between values, if it’s slightly off maybe it will return 0.99.

You have a lot of code here so this is probably wrong but not far off; I think you want some check like this

if startCFrame.LookVector:Dot(cameraCFrame.LookVector) > 0.5 then
    -- rotate

You can use math.atan2(lookVector.Z, lookVector.X) to get the angle on the Y axis of a directional vector. subtract the lookVector’s angle of the camera to the HRP and if its over 45 degrees, set the HRPs cframe.

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