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

People who like this

0 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. My framerate in the stats viewer goes from 2600 frames a second.

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

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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

just curious -- could it be somet$$anonymous$$ng else causing the problem?

Like literally in say 1980 (t$$anonymous$$rty+ 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 $$anonymous$$gh 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
aldonaletto
AlucardJay

People who like this

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

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

avatar image

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
Fattie

People who like this

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

How to find an intercept on a moving target 2 Answers

Position between objects, vector math. 1 Answer

Changing the forward rotation for LookAt 2 Answers

Get an offset behind player forward without target 1 Answer


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