Game Development Reference
In-Depth Information
Getting ready
The hypotenuse of a triangle is the longest side of a right-angled triangle, as shown in the
following diagram:
If the hypotenuse is denoted as h, the Pythagorean theorem can be written as follows:
h 2 = a 2 +b 2
If you take the square root of both the sides, you will get the following:
h = sqrt(a 2 +b 2 )
This means that if we know the length of any two sides of a right-angled triangle, we can
easily find the length of the third side.
When working with the game's Artificial Intelligence (AI), we will be using the
Pythagorean theorem frequently to calculate which agent is closer to the object. If side A is
bigger than side B, then it will always be bigger, irrespective of whether the lengths are
squared or not. Now, we can avoid taking the square roots to compare the distance. Instead,
we can just compare the squared values.
Search WWH ::




Custom Search