VOOZH about

URL: https://minecraft.wiki/w/Rotation

⇱ Rotation – Minecraft Wiki


Rotation

From Minecraft Wiki
Jump to navigation Jump to search
This article needs cleanup to comply with the style guide.
 [discuss]
Please help improve this page. The talk page may contain suggestions.
Reason: rewrite phrases in the second person.
πŸ‘ Image
Perspectives

Rotation (also known as perspective, viewpoint or viewing angle) is the direction an entity is facing. Rotation in Minecraft consists of Y-rotation or yaw and X-rotation, declination or pitch, each affecting the directions of the body and the head of the entity. For entities without heads, they can sometimes rotate entirely around the X-axis. The "X" and "Y" refers to the axis about which they rotate. Rotation can limit what a mob or player can see, but other entities (e.g. boats and item frames) also have a rotation.

Representation

[edit | edit source]

Entity hitbox

[edit | edit source]
πŸ‘ Image
A frog's perspective can be seen as a blue line in the debug renderer.

Rotation is visualized by entity_hitboxes debug renderer as a long blue tint placed in-line with the (red) eye height hitbox and shows which direction the entities are looking.

Entity format

[edit | edit source]
Main article: Entity format

Rotation is internally represented with two float values in degrees.

  • Y-rotation varies from -180Β° (facing due north) to -90Β° (facing due east) to 0Β° (facing due south) to +90Β° (facing due west) to +180Β° (facing due north again).
  • For X-rotation, horizontal is 0Β°, with positive values looking downward and negative values looking upward. It does not exceed positive or negative 90Β°.

Debug screen

[edit | edit source]
Main article: Debug screen
πŸ‘ Image
Facing in the Debug screen

With + , the rotation of all entities show up as a blue beam.

The player's own rotation can be seen in the debug screen under Facing. First the cardinal direction and axis are mentioned, followed by the two angles for direction and head tilt.

Y-rotation (Yaw Angle)

[edit | edit source]

A change in the Y-rotation angle changes the direction it is facing, to the left or right of its direction of motion.[1] They are represented in the debug screen correct to 1 decimal place. (The X and Z coordinates are represented correct to 3 decimal places.)

Here, "anticlockwise angle from +X in a 2D system" is thought of as anything in (-180Β°, 180Β°], or -180Β° < x ≀ 180Β°, where x is one of the angles.

Y-rotation angle ranges based on the cardinal directions
Cardinal

Directions

Towards the axis Y-rotation angle range

(ranges inclusive, follows anticlockwise direction)

Range of anticlockwise angle from +X in a 2D system

(ranges inclusive, anticlockwise direction)

North negative Z -135.1Β° to 135.0Β° (135.0Β°..180.0Β° βˆͺ -179.9Β°..-135.1Β°) 45.1Β° to 135.0Β°
South positive Z 44.9Β° to -45.0Β° -134.9Β° to -45.0Β°
East positive X -45.1Β° to -135.0Β° -44.9Β° to 45.0Β°
West negative X 134.9Β° to 45.0Β° 135.1Β° to -135.0Β°
πŸ‘ Diagram of a clock mapping yaw angles on a clock, highlighting the different cardinal directions in alternating black and white colours. The bounding angles are written on a white box in a black background.
Diagram mapping Y-rotation angles to clock positions and cardinal directions, along with the bounding angles (all inclusive) for each cardinal direction. This diagram has been referred to as the "yaw table" in this article.
Y-rotation angles based on the clock positions
Clock

Positions

Y-rotation angle Anticlockwise angle from +X in a 2D system
1 o'clock -150.0Β° 60.0Β°
2 o'clock -120.0Β° 30.0Β°
3 o'clock -90.0Β° 0.0Β°
4 o'clock -60.0Β° -30.0Β°
5 o'clock -30.0Β° -60.0Β°
6 o'clock -0.0Β° -90.0Β°
7 o'clock 30.0Β° -120.0Β°
8 o'clock 60.0Β° -150.0Β°
9 o'clock 90.0Β° 180.0Β°
10 o'clock 120.0Β° 150.0Β°
11 o'clock 150.0Β° 120.0Β°
12 o'clock 180.0Β° 90.0Β°

Algorithm for the Y-rotation angle

[edit | edit source]

Explanation

[edit | edit source]

The angle transformation to get the correct Y-rotation angle not only requires rotating the Y-rotation circle, but also reflecting the yaw table horizontally or vertically through the diameter.

Initial and Desired

[edit | edit source]
πŸ‘ A semicircle in Minecraft, placed in a valley using spruce logs and jungle place. Orientation is like a dome.
This is the upper half of a normal circle with the actual angles written. This picture can be compared with the one given above. We want to get the corresponding Y-rotation angles.

This part can be thought of as the top half of a semicircle standing on the +X axis. The circle is to be rotated for getting the outputs as in the yaw table. It is also checked whether reflecting the circle along the diameter (or flipping the circle) is necessary.

πŸ‘ A semicircle in Minecraft, placed in a valley using spruce logs and jungle planks. Orientation is towards the left. Mirror of the "Semicircle rotated by minus 90 degrees" image.
The desired angles. The 180 degree part is above the 0 degree part, and the semicircle is in a C-like orientation.
What we want
Initial angle

(+X axis, anticlockwise)

Desired angle

(Corresponding Y-rotation angle)

Orientation Desired position in the semicircle
0Β° -90Β° Towards the left Bottom
90Β° 180Β° Left
180Β° 90Β° Top
πŸ‘ Semicircle rotated by plus 90 degrees, orientation of the semicircle is towards the left.
Semicircle rotated by +90Β°.

Adding 90Β°

[edit | edit source]
Initial angle

(+X axis, anticlockwise)

Final angle

(Corresponding Y-rotation angle)

Orientation Final position in the semicircle
0Β° 90Β° Towards the left Top
90Β° 180Β° Left
180Β° -90Β° Bottom

Reflecting the semicircle along the (imaginary) horizontal diameter produces the desired angles (Top changes to bottom and vice-versa).

πŸ‘ Semicircle rotated by minus 90 degrees, orientation of the semicircle is towards the right.
Semicircle rotated by -90Β°.

Subtracting 90Β°

[edit | edit source]
Initial angle

(+X axis, anticlockwise)

Final angle

(Corresponding Y-rotation angle)

Orientation Final position in the semicircle
0Β° -90Β° Towards the right Bottom
90Β° 0Β° Right
180Β° 90Β° Top

Reflecting the semicircle along the vertical diameter produces the desired angles (Right changes to left and vice-versa).

Wrapping back

[edit | edit source]

For the yaw, the range is (-180Β°, 180Β°], which means that anything greater than the absolute value of 180 degrees must be wrapped back inside the yaw table. However, after the angle transformations, all the angles beyond the range are to be wrapped.

There can be many more approaches for wrapping other than the ones stated below.

Approach 1: Using the modulus

[edit | edit source]

Required: the size and the minimum and the maximum values.

The size is 360Β° because the whole circle is being considered.

Therefore,

In various programming languages, the mod(a, n) operator is used. When exactly one of the operands is negative, the basic definition breaks down, and programming languages differ in how these values are defined.[2] Here, n = 360. Therefore, 'a' should be changed to a positive value before performing the modulo operation.

Approach 2: Adding or subtracting by 360 degrees

[edit | edit source]

360 degrees is a full revolution. Moving by positive or negative 360 degrees is the same thing as not moving inside the orbit.

Thus, we can use:

This has been achieved through the following code in JavaScript:

angle=-360*Math.sign(angle)+angle;
if(angle===-180)
return"180.0";
returnangle;

Here, angle is the variable x.

The final code

[edit | edit source]

Here is the final code in JavaScript. There are two coordinates here, namely (xcurrent, zcurrent) and (xdest, zdest).[3]

functiongetYawAngle(xcurrent,zcurrent,xdest,zdest){

// z is negated here (equivalent to -(zdest - zcurrent))
letslope=Math.atan2(zcurrent-zdest,xdest-xcurrent)*(180/Math.PI);

slope+=90;// Adding 90 degrees
slope*=-1;// Reflecting along the horizontal diameter

// Wraps into the (-180, 180] range (Approach 2)
if(Math.abs(slope)>180){
slope=-360*Math.sign(slope)+slope;
}

// Rounding to a single decimal place
slope=Math.round(slope*10)/10;

// Mimicking the Java special‑case string outputs
if(slope===0)return"-0.0";
if(slope===-180)return"180.0";

// Default path – always keeping one decimal digit like Java’s β€œβ€‘123.4”
returnslope.toFixed(1);
}

The function in Approach 2 has not been replicated one-to-one.

Place blocks

[edit | edit source]

The viewing angle affects the placement of some blocks: depending on how the player look, for example, a banner or a sign rotated accordingly. The viewing angle also plays a role when placing stairs or scaffolding.

Target selection

[edit | edit source]

Target selection properties allow entities to be selected that have a specific viewing angle:

y_rotation Viewing angle
x_rotation Head tilt angle

Angle ranges are specified with two points, e.g. B. 43..47.

/title @a[y_rotation=<view angle>] actionbar {"text":"View direction (compass direction)"}
/title @a[x_rotation=<head tilt angle>] actionbar {"text":"head tilt (up)"}

Examples of the cardinal directions:

/execute if entity @p[y_rotation=135..-135] run say North
/execute if entity @p[y_rotation=-135..-45] run say East
/execute if entity @p[y_rotation=-45..45] run say South
/execute if entity @p[y_rotation=45..135] run say West

Save perspective

[edit | edit source]

Blinking angles can be read out and saved in a score: To do this, create a score target for the direction and the inclination.

/scoreboard objectives add direction dummy "viewing angle direction" 
/scoreboard objectives add tilt dummy "viewing angle inclination"

Then, read out the direction and inclination using the command /data and save them in the respective score.

/execute as @a store result score @s direction run data get entity @s Rotation[0]
/execute as @a store result score @s tilt run data get entity @s Rotation[1]

Set perspective

[edit | edit source]

The commands /teleport and /rotate can be used to set the perspective of entities. The entities can move freely after teleportation if they have AI, but they start with the fixed viewing angle.

Additionally, all entities except players can be realigned using the command /data via the property Rotation

Viewpoint coordinates

[edit | edit source]

Circumflexes (^) allow the position to be determined depending on the rotation of an entity.

History

[edit | edit source]
This section of the article is empty.
 
You can help by expanding it.

References

[edit | edit source]

Navigation

[edit | edit source]
Retrieved from "https://minecraft.wiki/w/Rotation?oldid=3638591"

Navigation menu