What Causes CFrame To Return NAN / Fail Construction

For example,

The first Vector3 is Position, and the 2nd Vector3 is LookAt.
image
The final print is the CFrame.

In the case of my code “Origin” is the first V3 printed out, and “ToPos” are in the 2nd V3 printed out. Separated by the blue line.
“Origin” is the current position, and ToPos is the LookAt. Both are Vector3. The reason Origin.Y is the Y coord of the LookAt is because I don’t want the CFrame to angle towards the ToPos.Y position. Hence using Origin.Y.

And again the 3rd printed item is the CFrame construction (attempt).

When I construct a CFrame like this; CFrame.new(Origin,Vector3.new(ToPos.X,Origin.Y,ToPos.Z)) it sometimes causes it to fail and returns NAN for certain vectors of the CFrame. Sometimes, but not always.

Why does this happen and how do I prevent this?

It would be helpful to know what ToPos and Origin is.
Maybe show how you get those vectors?

2 Likes

try printing all the different values fed into the CFrame.new()

print(Origin)
print(Vector3.new(ToPos.X,Origin.Y,ToPos.Z))

See if anything returns something odd, and if they do, check if its when the CFrame returns NAN

1 Like

Sorry I had forgotten to mention, “Origin” is the first V3 printed out, and “ToPos” are in the 2nd V3 printed out. Separated by the blue line here.
image
“Origin” is the current position, and ToPos is the LookAt. Both are Vector3. The reason Origin.Y is the Y coord of the LookAt is because I don’t want the CFrame to angle towards the ToPos.Y position. Hence using Origin.Y.

And again the 3rd printed item is the CFrame construction (attempt).

it may be because Origin and ToPos are identical to each other.

2 Likes

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