Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion api/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const determineDesiredShapeType = (animationName) => {
return "vertical";
};

const isOnSurface = (physicsMesh) => {
return typeof flock?.checkIfOnSurface === "function" &&
flock.checkIfOnSurface(physicsMesh);
};

const updateCapsuleShapeForAnimation = (physicsMesh, animationName) => {
if (
!physicsMesh ||
Expand All @@ -28,7 +33,15 @@ const updateCapsuleShapeForAnimation = (physicsMesh, animationName) => {
return;
}

const desiredShapeType = determineDesiredShapeType(animationName);
let desiredShapeType = determineDesiredShapeType(animationName);

// The horizontal capsule is designed for airborne movement. When a Fly
// animation is used on a surface (e.g. swimming), keep the vertical capsule
// so the character doesn't become unstable on slopes near the water's edge.
if (desiredShapeType === "horizontal-fly" && isOnSurface(physicsMesh)) {
desiredShapeType = "vertical";
}

if (!physicsMesh.metadata) physicsMesh.metadata = {};

if (physicsMesh.metadata.currentPhysicsShapeType === desiredShapeType) {
Expand Down
Loading