Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Calculating rotation of character in radians gives me "-nan(ind)" when I move without using mouse look. It only happens once in a run (from what I experienced), but it is annoying and straight up bad. Thing is, it only returns such value from "Math.acos" part, whole thing without it gives normal number instead of this. Why can this happen? Here's how this variable looks: var rawX = Math.acos ((t1.x*t2.x + t1.y*t2.y + t1.z*t2.z) / (Math.sqrt (t1.x*t1.x + t1.y*t1.y + t1.z*t1.z) * Math.sqrt (t2.x*t2.x + t2.y*t2.y + t2.z*t2.z))); |
||||
|
You should make sure that the value you are using for Math.acos() is between 1 and -1 otherwise it will return "-nan" hope that helps |
||||
|
I guess, you can try to log the t1 and t2 values in case rawX is NaN, so you can catch the input which causes the error. It actually throws NaN even if you have something like 1.00000001, which you can get if you have any other floating point operation with your t1 and t2 props before. So if it doesn't affect you in any way and you just don't want the error message to appear you can use a clamp function to force the input between -1 and 1. I don't recommend this, but it's something that I would do:) function clamp(number, min, max) { |
||||
|
Hey, so, knowing that it returns this weird value if it is larger than 1 or lower than -1, I basically capped the value: ... Don't know if this way is good or not, but nothing bad happened from it. In fact, the issue is solved (for now), so, works for me I guess. It also solved one other issue I had, but that is to be kinda expected. Thanks guys! |
|