Better (?) gravity and jumps
This commit is contained in:
parent
499919a6a0
commit
fa1a597fb8
|
@ -186,7 +186,7 @@ export class RunningEngine {
|
|||
|
||||
this.engine.runRenderLoop(() => {
|
||||
this.performanceMonitor.sampleFrame();
|
||||
this.scene.gravity = this.gravity.scale(this.performanceMonitor.averageFrameTime / 1000.0);
|
||||
this.scene.gravity = this.gravity.scale(this.frameRateScale);
|
||||
try {
|
||||
Array.from(navigator.getGamepads()).forEach(gp => {
|
||||
if (gp !== null) this.checkGamepadInput(gp);
|
||||
|
@ -209,6 +209,10 @@ export class RunningEngine {
|
|||
c.ellipsoid = new Vector3(0.25, this.options.initialPos.y / 2, 0.25);
|
||||
}
|
||||
|
||||
get frameRateScale(): number {
|
||||
return this.performanceMonitor.averageFrameTime / 1000.0;
|
||||
}
|
||||
|
||||
get inXR(): boolean {
|
||||
return (this.xr !== null) && (this.xr.baseExperience.state === WebXRState.IN_XR);
|
||||
}
|
||||
|
@ -295,7 +299,7 @@ export class RunningEngine {
|
|||
|
||||
jump() {
|
||||
if (Math.abs(this.camera.cameraDirection.y) < 0.1) {
|
||||
this.camera.cameraDirection.y += 1;
|
||||
this.camera.cameraDirection.y += 1 * this.frameRateScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
src/index.ts
18
src/index.ts
|
@ -22,6 +22,18 @@ assertion type SceneHandle(ds: Embedded<Ref>);
|
|||
|
||||
function interpretScene(myId: string, runningEngine: RunningEngine, rootMesh: Mesh, sceneDs: Ref) {
|
||||
at sceneDs {
|
||||
during SceneProtocol.Gravity($direction: Shapes.LiteralVector3) => {
|
||||
Turn.active.sync(sceneDs).then(() => {
|
||||
console.log('enabling gravity');
|
||||
runningEngine.applyGravity = true;
|
||||
});
|
||||
on stop {
|
||||
console.log('disabling gravity');
|
||||
runningEngine.applyGravity = false;
|
||||
}
|
||||
runningEngine.gravity = new Vector3(direction.x, direction.y, direction.z);
|
||||
}
|
||||
|
||||
during Shapes.Sprite({ "name": $name: string, "formals": $formals }) => spawn named `sprite:${name}` {
|
||||
if (name === myId) {
|
||||
console.log('ignoring sprite', name);
|
||||
|
@ -52,12 +64,6 @@ function spriteMain(env: Environment, runningEngine: RunningEngine, rootMesh: Me
|
|||
currentShape = currentShape.reconcile(env, env.spriteName, shape);
|
||||
currentShape.rootnode.parent = rootMesh;
|
||||
}
|
||||
|
||||
during SceneProtocol.Gravity($direction: Shapes.LiteralVector3) => {
|
||||
runningEngine.applyGravity = true;
|
||||
on stop runningEngine.applyGravity = false;
|
||||
runningEngine.gravity = new Vector3(direction.x, direction.y, direction.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue