Fix animations

This commit is contained in:
jordan4ibanez 2024-04-21 05:41:16 -04:00
parent c71e914ebc
commit deed42a2f5
2 changed files with 71 additions and 53 deletions

View File

@ -14,6 +14,7 @@ namespace animationStation {
animationProgress: number = 0;
up: boolean = true;
speed: number = 1.0;
newAnimationTrigger: boolean = true;
}
/**
@ -341,9 +342,15 @@ namespace animationStation {
currentAnimationState = playerAnimationState.get(playerName) as PlayerAnimationState;
}
// Already had this animation.
if (currentAnimationState.currentAnimation == animation) {
return;
}
currentAnimationState.currentAnimation = animation;
currentAnimationState.animationProgress = 0;
currentAnimationState.up = true;
currentAnimationState.newAnimationTrigger = true;
}
export function setPlayerAnimationSpeed(playerName: string, animationSpeed: number) {
@ -397,7 +404,7 @@ namespace animationStation {
return;
}
if (currentAnimationState.currentAnimation == "" && currentAnimationState.animationProgress != 0) {
if (currentAnimationState.currentAnimation == "" && currentAnimationState.newAnimationTrigger == true) {
// No animation, reset.
workerAnimationPointEnd.identity();
@ -417,6 +424,7 @@ namespace animationStation {
currentAnimationState.animationProgress = 0;
currentAnimationState.up = true;
currentAnimationState.newAnimationTrigger = false;
return;
}

View File

@ -5,6 +5,7 @@ namespace playerModel {
const Quaternion = utility.Quaternion;
const registerAnimation = animationStation.registerAnimation;
const registerBones = animationStation.registerBones;
const setPlayerAnimation = animationStation.setPlayerAnimation;
const setPlayerAnimationSpeed = animationStation.setPlayerAnimationSpeed;
const create3d = vector.create3d;
/*
@ -19,57 +20,59 @@ namespace playerModel {
*/
registerAnimation("character.b3d", "idle", new Map([
["Arm_Left", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}],
["Leg_Right", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}],
registerAnimation("character.b3d",
"walk",
new Map([
["Arm_Left", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}],
["Leg_Right", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}],
["Arm_Right", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}],
["Leg_Left", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}]
]));
["Arm_Right", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}],
["Leg_Left", {
start: {
translation: create3d(0, 0, 0),
rotation: create3d(-math.pi / 4, 0, 0),
scale: create3d(0, 0, 0)
},
end: {
translation: create3d(0, 0, 0),
rotation: create3d(math.pi / 4, 0, 0),
scale: create3d(1, 1, 1)
}
}]
]));
registerBones("character.b3d", [
"Body",
@ -92,7 +95,7 @@ namespace playerModel {
visual_size: vector.create3d(1, 1, 1)
});
animationStation.setPlayerAnimation(name, "idle");
});
// speed based animation
@ -102,7 +105,14 @@ namespace playerModel {
let vel = player.get_velocity();
let speed = vector.length(vel);
const name = player.get_player_name();
setPlayerAnimationSpeed(name, speed);
if (speed == 0) {
setPlayerAnimation(name, "");
} else {
setPlayerAnimation(name, "walk");
setPlayerAnimationSpeed(name, speed);
}
}
});