Common class usage explanations

Source: Internet
Author: User

1, vector3.magnitude length

Returns the length of the vector (read-only).

The length of the vector is

If you need to compare the lengths of some vectors, you can compare the squares of their lengths, using Sqrmagnitude (the squared calculation is fast).

So: When comparing the length of vectors, use the following sqrmagnitude method Best!

It is also best to use sqrmagnitude when detecting the position of a person in the update from the target location!

Similar to this: if ((perpos-targetposition). Sqrmagnitude < 1.0f) {}

2, vector3.sqrmagnitude length square

Returns the square of the length of this vector (read-only).

The length of the vector is calculated by using the Pythagorean theorem, the computation of two times and open root of the computer is more time consuming than adding and subtracting. So if you want to compare the lengths of two vectors, you can get a lot faster with sqrmagnitude.

Common class usage explanations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.