Hardware Reference
In-Depth Information
The function calculates the distance by:
1. Working out the difference between the x,y,z values in point1 and
point2:
xd = point2.x - point1.x
yd = point2.y - point1.y
zd = point2.z - point1.z
2. Calculating the squares of the difference between the points:
xd*xd
3. Adding together all the squares:
(xd*xd) + (yd*yd) + (zd*zd)
4. Returning the difference between the two points, which is the
square root of the sum of the squares using the Python function
math.sqrt():
return math.sqrt((xd*xd) + (yd*yd) + (zd*zd))
Visit www.mathsisfun.com/algebra/distance-2-points.html to learn about
Pythagoras' theorem and how to use it to calculate the distance between
two points.
The block friend is moved toward the player by finding the blocks between the
block friend and the player, and looping through those blocks:
for blockBetween in blocksBetween[:-1]:
The [:-1] tells Python to loop through all the blocks in the blocksBetween
list until it gets to the last but one block. This way, when the block friend is
moved toward the player, she stands next to the player and not on top of him.
The square root of a number is the value that can be multiplied by itself to give
that number. For example, the square root of 9 is 3, because 3 x 3 = 9.
 
Search WWH ::




Custom Search