im using arctangent2 to find the angle between 2 vectors.
arctan2(magnitude(axis of rotation), dotProduct(start vector,end vector));
so rotating from vector1 direction to vector 2 direction along axis “axis”
angle degrees where angle is that arctan function.
Problem is it requires square rooting. Can i arctangent with a square adn get the right answer still?
OK COMPLETELY WRONG It was a debug draw function that was running in update that trashed the framerate my bad. it was drawing debug lines with 5 second lifespans every update so hundreds stacked on eachother and THAT was trashing framerate. So ignore all this.
just curious – could it be something else causing the problem?
Like literally in say 1980 (thirty+ years ago) you’d hear people say “if possible avoid a square root!”
That’s irrelevant today. Consider how many calculations Unity is doing all the time man ??! All the rotations and so on… every single frame… I mean … my goodness … it’s not even a compiled language, you’re using vast layers of interpreters, physics engines, and what not.
I use and I see used Atan2 constantly, in fairly high performance code (every sort of typical 3D game etc), eg…
Don't mind, @Fattie - you deserved the up vote, and questions solved don't give us karma anyway. You're right about square roots: even mobile devices have a FPU to spit thousands of floating point operations per frame, including square roots.
that's weird dude ... no karma for Ticks huh ??? Only for thumbs .. is that correct? Seems hard to believe. (Of course I don't really mind - I was just kidding around.)
Despite the high rate of calculation of most devices nowadays, I still consider little details like avoiding sqr root, trig functions or other recursive function. Even if they tend to make code less readable... And right answer (when ticked) do give Karma if it is ticked by someone else. As if you still need some.
"And right answer (when ticked) do give Karma" ... ah that makes sense. thanks for the info. ("when ticked by someone else" .. indeed) "As if you still need some." I don't know how you can say that man! I need SO MUCH MOAR :) I can't agree with you on sqrroot and trig man. You should use them very freely. Regarding recursion, never use it, for sure.
was a debug.drawray running every update and creating rays that lasted 5 seconds.
My bad.
Question answered cause it doesnt need an answer.
we happened to answer at the same time, on my screen there wasnt even an answer when i went to reply :P You'll notice i got posted first. you've been marked though :)
OK COMPLETELY WRONG It was a debug draw function that was running in update that trashed the framerate my bad. it was drawing debug lines with 5 second lifespans every update so hundreds stacked on eachother and THAT was trashing framerate. So ignore all this.
– sparkzbarca