Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sparkzbarca · Mar 25, 2013 at 02:07 PM · mathvectorstrigonometry

Math question, angles and magnitude stuff

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparkzbarca · Mar 25, 2013 at 03:00 PM 0
Share

my frame rate is getting hammered. Basically this is running in update. and yea it's just smashing the shit out of the frame rate. And running outside of update doesnt seem viable. The algorithm based on appearances it gets more and more accurate every second.

I've not idea why but literally, this is rotating in update adn yet i can watch it slowly rotate around like it was lerping.

That is just trashing framerate to do so. I can live without it (it's just a CPU load not a GPU so it's honestly not a huge issue for a computer game, and its only ever going to run one at a time, it's an editor to snap 2 objects together).

So i can totally run it and live with it as is. It only slows framerate while it snaps stuff together (though that does take literally a second or two)

But if i dont have to i dont want to. It really is very very noticable the drag. $$anonymous$$y framerate in the stats viewer goes from 2600 frames a second.

avatar image sparkzbarca · Mar 25, 2013 at 03:01 PM 1
Share

O$$anonymous$$ CO$$anonymous$$PLETELY 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.

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Fattie · Mar 25, 2013 at 02:13 PM

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...

 __angleCCW = Mathf.Atan2(b.z,b.x) - Mathf.Atan2(a.z,a.x);

So ... just a thought man ! Maybe forget about it :)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aldonaletto · Mar 25, 2013 at 04:32 PM 0
Share

Don't $$anonymous$$d, @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.

avatar image Fattie · Mar 25, 2013 at 04:59 PM 0
Share

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 $$anonymous$$d - I was just kidding around.)

avatar image fafase · Mar 25, 2013 at 05:06 PM 0
Share

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 $$anonymous$$arma if it is ticked by someone else. As if you still need some.

avatar image Fattie · Mar 25, 2013 at 05:10 PM 0
Share

"And right answer (when ticked) do give $$anonymous$$arma" ... 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 $$anonymous$$UCH $$anonymous$$OAR :)

I can't agree with you on sqrroot and trig man. You should use them very freely.

Regarding recursion, never use it, for sure.

avatar image
1

Answer by sparkzbarca · Mar 25, 2013 at 03:01 PM

wasnt square root fucntion

was a debug.drawray running every update and creating rays that lasted 5 seconds.

My bad.

Question answered cause it doesnt need an answer.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparkzbarca · Mar 26, 2013 at 12:12 PM 1
Share

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 :)

avatar image Fattie · Mar 26, 2013 at 12:50 PM 0
Share

LOL thanks man :-) You rock ...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating a parabola line in 3D Space 1 Answer

Position between objects, vector math. 1 Answer

Changing the forward rotation for LookAt 2 Answers

How to find an intercept on a moving target 2 Answers

How to get a vector3 (postion) 1 unit away from another in the direction of a 3rd vector3? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges