Skip to content

Player Model Event

liopyu edited this page Aug 20, 2024 · 2 revisions

The PlayerModelEvent is an event used within the animation framework to interact with the player model and its animation parameters during the setup animation phase. This event provides access to various properties and methods related to the player model's animations.

Example Usage

Below is a basic example of how to use the PlayerModelEvent within an animation script:

AnimationJS.playerModel(event => {
    const { playerModel, entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch } = event;
    // Use the playerModel and animation parameters as needed
});

Methods

getPlayerModel

Retrieves the player model associated with the current animation context.

Example Usage:

const playerModel = event.getPlayerModel();

getAgeInTicks

Retrieves the age of the entity in ticks, used for animations that depend on the entity's lifetime.

Example Usage:

const ageInTicks = event.getAgeInTicks();

getHeadPitch

Retrieves the pitch of the entity's head, used for controlling vertical head movement in animations.

Example Usage:

const headPitch = event.getHeadPitch();

getLimbSwing

Retrieves the limb swing value, which represents the movement of the entity's limbs (e.g., legs) during walking animations.

Example Usage:

const limbSwing = event.getLimbSwing();

getLimbSwingAmount

Retrieves the limb swing amount, which represents the intensity or magnitude of the limb swing during animations.

Example Usage:

const limbSwingAmount = event.getLimbSwingAmount();

getNetHeadYaw

Retrieves the yaw of the entity's head, used for controlling horizontal head movement in animations.

Example Usage:

const netHeadYaw = event.getNetHeadYaw();

Detailed Example

Here is a more detailed example that combines the use of multiple methods to make the player "wave":

// Make the player wave their left arm back and forth to "wave"
AnimationJS.playerModel(event => {
	const { playerModel, entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch } = event;
	if (!entity.persistentData.runTime) entity.persistentData.runTime = 0
	if (!entity.persistentData.runTimeMode) entity.persistentData.runTimeMode = "init"
	if ((entity.persistentData.runTime <= 0 && entity.persistentData.runTimeMode == "down") || entity.persistentData.runTimeMode == "init") {
		entity.persistentData.runTimeMode = "up"
	} else if (entity.persistentData.runTime >= 40 && entity.persistentData.runTimeMode == "up") {
		entity.persistentData.runTimeMode = "down"
	}
	if (entity.persistentData.runTimeMode == "up") {
		entity.persistentData.runTime++
	} else if (entity.persistentData.runTimeMode == "down") {
		entity.persistentData.runTime--
	}
	playerModel.leftArm.setRotation(
		playerModel.leftArm.xRot * 1.5 - (0.02 * entity.persistentData.runTime),
		playerModel.leftArm.yRot * 1.5,
		playerModel.leftArm.zRot * 1.5 - (0.1 * entity.persistentData.runTime)
	)
	playerModel.leftSleeve.copyFrom(playerModel.leftArm)
});

Clone this wiki locally