Breaking It Down

In the turn function, why do we set the direction to values like Math.PI and -Math.PI/2?

Recall from Geometry, that angles, the amount of rotation, use radians instead of degrees. The avatar starts facing backward, toward the camera. So 0° of rotation is 0 radians of rotation, which means facing backward. And 180° is pi radians, which means facing forward into the screen. The following table is the complete list we’re using in the turn function.

Direction

Degrees

Radians

JavaScript

Forward

180°

pi

Math.PI

Right

90°

pi ÷ 2

Math.PI/2

Left

-90°

-pi ÷ 2

-Math.PI/2

Backward

0

0

Why rotation.y?

So that explains the number that we use for the direction variable in the function turn, but why do we set rotation.y? Why not rotation.z or rotation.x

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.