HeadRotation
Look direction for entities. Separate from body rotation in TransformComponent.
Access
Section titled “Access”HeadRotation head = store.getComponent(ref, HeadRotation.getComponentType());Basic Operations
Section titled “Basic Operations”// get rotation vector (pitch, yaw, roll in radians)Vector3f rotation = head.getRotation();float pitch = rotation.getPitch(); // vertical angle (look up/down)float yaw = rotation.getYaw(); // horizontal angle (look left/right)float roll = rotation.getRoll(); // tilt angle
// set rotationhead.getRotation().assign(pitch, yaw, roll);head.setRotation(rotationVector);
// teleport rotation (skips NaN values)head.teleportRotation(new Vector3f(pitch, yaw, roll));Direction Vectors
Section titled “Direction Vectors”// get normalized look direction (3D vector)Vector3d direction = head.getDirection();
// get axis-snapped direction (-1, 0, or 1 per axis)Vector3i axisDir = head.getAxisDirection();
// get horizontal axis direction (ignores pitch)Vector3i horizontalDir = head.getHorizontalAxisDirection();
// get dominant axisAxis axis = head.getAxis(); // X, Y, or ZAxis Enum
Section titled “Axis Enum”The Axis enum represents X, Y, or Z:
Axis axis = head.getAxis();Vector3i axisVector = axis.getDirection(); // (1,0,0), (0,1,0), or (0,0,1)
// rotate a vector around this axisaxis.rotate(vector, angle);
// flip a vector along this axisaxis.flip(vector);Examples
Section titled “Examples”Look at Position
Section titled “Look at Position”HeadRotation head = store.getComponent(ref, HeadRotation.getComponentType());TransformComponent transform = store.getComponent(ref, TransformComponent.getComponentType());
Vector3d entityPos = transform.getPosition();Vector3d targetPos = new Vector3d(x, y, z);Vector3d direction = targetPos.clone().subtract(entityPos).normalize();
// calculate pitch and yaw from directionfloat pitch = (float) Math.asin(-direction.getY());float yaw = (float) Math.atan2(direction.getX(), direction.getZ());
head.getRotation().assign(pitch, yaw, 0);Get Look Transform (with Eye Height)
Section titled “Get Look Transform (with Eye Height)”Use TargetUtil.getLook() to get the full look transform including eye height:
Transform lookTransform = TargetUtil.getLook(ref, store);// includes position at eye level + head rotationCardinal Direction Check
Section titled “Cardinal Direction Check”HeadRotation head = store.getComponent(ref, HeadRotation.getComponentType());Vector3i facing = head.getHorizontalAxisDirection();
if (facing.getZ() > 0) { // facing south (+Z)} else if (facing.getZ() < 0) { // facing north (-Z)} else if (facing.getX() > 0) { // facing east (+X)} else { // facing west (-X)}Player Input
Section titled “Player Input”For players, head rotation is updated automatically from client input via PlayerInput.SetHead. The rotation syncs each tick based on where the player is looking.
Relationship to TransformComponent
Section titled “Relationship to TransformComponent”HeadRotation- where the entity is looking (head/eyes)TransformComponent.getRotation()- body orientation
For most gameplay purposes (raycasting, targeting), use HeadRotation. The body rotation is primarily for visual rendering.