|
Got a function that uses a lot of trig
It used to quite regularly return Vector3(NaN, NaN, NaN) when on a flat (Vector3 == Vector3.Up) even though it shouldn't.
So I added the if (groundNormal == Vector3.up) return Vector3.zero; part and it got rid of most of the errors. But I still get the very rare occasional one and I'd like to get rid of it. Any ideas? Bonus Question which will probably solve original question so I'll leave it in same answer. Haven't really done vectors/trig in maybe 6 years so I'm a bit rusty. But does anyone know how to rewrite my function a lot cleaner? I'm pretty sure there are ways to do it using cross products etc. Pretty much the function is manually calculating the force in the x,y,z direction on a slope for gravity.
(comments are locked)
|
|
Think I've solved this by adding
Up the top. Guess normal was returning a number marginally over 1 due to floating point error or something. Regarding the numerical errors, you should probably clamp the input to Acos() to the range [-1, 1] rather than clamping the vector's magnitude. The latter might work in this case, but the former is the generally accepted method of ensuring that the input to Acos() is valid.
Mar 04 '11 at 07:10 AM
Jesse Anders
(comments are locked)
|
