Add stair height smoothing and update navigation controllers
This commit is contained in:
@@ -626,6 +626,103 @@ describe("RapierCollisionWorld", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("autosteps up authored stairs when the top surface is within the max step height", async () => {
|
||||
const floorBrush = createBoxBrush({
|
||||
id: "brush-floor-stair-climb",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 8,
|
||||
y: 1,
|
||||
z: 10
|
||||
}
|
||||
});
|
||||
const stepOne = createBoxBrush({
|
||||
id: "brush-stair-step-one",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 0.1,
|
||||
z: 0.75
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 0.2,
|
||||
z: 0.5
|
||||
}
|
||||
});
|
||||
const stepTwo = createBoxBrush({
|
||||
id: "brush-stair-step-two",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 0.3,
|
||||
z: 1.25
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 0.6,
|
||||
z: 0.5
|
||||
}
|
||||
});
|
||||
const stepThree = createBoxBrush({
|
||||
id: "brush-stair-step-three",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 0.5,
|
||||
z: 1.75
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: 0.5
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Stair Climb Scene" }),
|
||||
brushes: {
|
||||
[floorBrush.id]: floorBrush,
|
||||
[stepOne.id]: stepOne,
|
||||
[stepTwo.id]: stepTwo,
|
||||
[stepThree.id]: stepThree
|
||||
}
|
||||
});
|
||||
const collisionWorld = await RapierCollisionWorld.create(
|
||||
runtimeScene.colliders,
|
||||
runtimeScene.playerCollider,
|
||||
{
|
||||
maxStepHeight: 0.25
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
let feetPosition = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: -0.4
|
||||
};
|
||||
|
||||
for (let index = 0; index < 10; index += 1) {
|
||||
feetPosition = collisionWorld.resolveFirstPersonMotion(
|
||||
feetPosition,
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0.25
|
||||
},
|
||||
runtimeScene.playerCollider
|
||||
).feetPosition;
|
||||
}
|
||||
|
||||
expect(feetPosition.z).toBeGreaterThan(1.6);
|
||||
expect(feetPosition.y).toBeGreaterThan(0.45);
|
||||
expect(feetPosition.y).toBeLessThan(0.62);
|
||||
} finally {
|
||||
collisionWorld.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("supports authored Player Start collision mode none without world clipping", async () => {
|
||||
const wallBrush = createBoxBrush({
|
||||
id: "brush-wall-no-collision",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { createIdleRuntimeLocomotionState } from "../../src/runtime-three/player
|
||||
import { stepPlayerLocomotion } from "../../src/runtime-three/player-locomotion";
|
||||
import type { PlayerStartActionInputState } from "../../src/runtime-three/player-input-bindings";
|
||||
import type { RuntimePlayerMovement } from "../../src/runtime-three/runtime-scene-build";
|
||||
import { smoothGroundedStairHeight } from "../../src/runtime-three/stair-height-smoothing";
|
||||
|
||||
const movementTemplate = createPlayerStartMovementTemplate();
|
||||
|
||||
@@ -638,6 +639,43 @@ describe("player-locomotion", () => {
|
||||
expect(step?.locomotionState.planarSpeed).toBeCloseTo(4.5);
|
||||
});
|
||||
|
||||
it("smooths grounded stair height changes instead of snapping", () => {
|
||||
const smoothedHeight = smoothGroundedStairHeight({
|
||||
currentSmoothedFeetY: 0,
|
||||
targetFeetY: 0.2,
|
||||
grounded: true,
|
||||
dt: 1 / 60,
|
||||
maxStepHeight: 0.5
|
||||
});
|
||||
|
||||
expect(smoothedHeight).toBeGreaterThan(0);
|
||||
expect(smoothedHeight).toBeLessThan(0.2);
|
||||
});
|
||||
|
||||
it("snaps grounded height smoothing when the player leaves the ground", () => {
|
||||
const smoothedHeight = smoothGroundedStairHeight({
|
||||
currentSmoothedFeetY: 0,
|
||||
targetFeetY: 0.2,
|
||||
grounded: false,
|
||||
dt: 1 / 60,
|
||||
maxStepHeight: 0.5
|
||||
});
|
||||
|
||||
expect(smoothedHeight).toBeCloseTo(0.2);
|
||||
});
|
||||
|
||||
it("snaps grounded height smoothing for ledge-sized vertical jumps", () => {
|
||||
const smoothedHeight = smoothGroundedStairHeight({
|
||||
currentSmoothedFeetY: 0,
|
||||
targetFeetY: 1,
|
||||
grounded: true,
|
||||
dt: 1 / 60,
|
||||
maxStepHeight: 0.35
|
||||
});
|
||||
|
||||
expect(smoothedHeight).toBeCloseTo(1);
|
||||
});
|
||||
|
||||
it("sinks toward the water surface while keeping the head above water", () => {
|
||||
const step = stepPlayerLocomotion({
|
||||
dt: 0.1,
|
||||
|
||||
Reference in New Issue
Block a user