Skip to content

Orientation API

The Orientation API enables you to control the player's rotation.

If you're here to search for a specific method or just a quick explanation of how something works, you may find it useful to scroll through your IDE tooltips of your IOrientation instance. This is a good method for discovering all possibilities you have, as Actor also has extensive Javadocs.

INFO

Orientation (rotation) is only set every ClientTick. Yet the player can rotate in sub-ticks using their mouse.
This may result in a blocky/snappy feel when setting or supplying rotation, but this is completely normal and the game does not care.

Obtaining the Orientation

You can obtain the API surface like this:

java
var orientation = YOUR_ACTOR.getOrientation();

Using the Orientation

Here is some info on how to use the Orientation API:

Setting rotation

java
// (yaw, pitch)
orientation.setRotation(90.0f, 0.0f);
// OR
orientation.setYaw(90.0f);
orientation.setPitch(0.0f);

TIP

Yaw is looking left/right and pitch is looking up/down.
Pitch is expected to be between -90 and 90.

Adding rotation

Instead of setting rotation directly, you can add it to the current player's rotation.

java
orientation.addRotation(15.0f, -10.0f);
// OR
orientation.addYaw(15.0f);
orientation.addPitch(-10.0f);

Supply rotation

You can also supply a player's rotation. This means passing a Supplier<Float> which should return the rotation (or yaw/pitch) the player should have.
These suppliers are queried every ClientTick.

java
AtomicInteger ticks = new AtomicInteger();

// Turn right and look up/down in a *sin* pattern
orientation.supplyRotation(
    () -> ticks.getAndIncrement() * 5f, // Yaw
    () -> (float) (Math.sin(ticks.get()*0.05f) * 40f) // Pitch
);

You can also supply both rotations separately:

java
orientation.supplyYaw(() -> 180.0f);
orientation.supplyPitch(() -> 0.0f);