Skip to content

Commit

Permalink
added control keybind to slow down
Browse files Browse the repository at this point in the history
  • Loading branch information
kpal81xd committed Apr 18, 2024
1 parent ea9a0ad commit 6c7223c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
19 changes: 15 additions & 4 deletions src/cameras/multi-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MultiCamera extends BaseCamera {

moveDamping: number = 0.98;

mousePanSpeed: number = 1;
mousePanSpeed: number = 0.0025;

mobilePanSpeed: number = 0.025;

Expand All @@ -37,6 +37,8 @@ class MultiCamera extends BaseCamera {

sprintSpeed: number = 4;

crouchSpeed: number = 1;

private _pointerEvents: Map<number, PointerEvent> = new Map();

private _lastPinchDist: number = -1;
Expand All @@ -54,7 +56,8 @@ class MultiCamera extends BaseCamera {
right: false,
up: false,
down: false,
sprint: false
sprint: false,
crouch: false
};

constructor(options: Record<string, any> = {}) {
Expand All @@ -68,6 +71,7 @@ class MultiCamera extends BaseCamera {
this.zoomExp = options.zoomExp ?? this.zoomExp;
this.moveSpeed = options.moveSpeed ?? this.moveSpeed;
this.sprintSpeed = options.sprintSpeed ?? this.sprintSpeed;
this.crouchSpeed = options.crouchSpeed ?? this.crouchSpeed;

this._onWheel = this._onWheel.bind(this);
this._onKeyDown = this._onKeyDown.bind(this);
Expand Down Expand Up @@ -182,6 +186,9 @@ class MultiCamera extends BaseCamera {
case 'shift':
this._key.sprint = true;
break;
case 'control':
this._key.crouch = true;
break;
}
}

Expand Down Expand Up @@ -209,6 +216,9 @@ class MultiCamera extends BaseCamera {
case 'shift':
this._key.sprint = false;
break;
case 'control':
this._key.crouch = false;
break;
}
}

Expand All @@ -233,7 +243,7 @@ class MultiCamera extends BaseCamera {
tmpV1.sub(this.entity.up);
}
tmpV1.normalize();
const speed = this._key.sprint ? this.sprintSpeed : this.moveSpeed;
const speed = this._key.crouch ? this.crouchSpeed : this._key.sprint ? this.sprintSpeed : this.moveSpeed;
tmpV1.mulScalar(this.sceneSize * speed * dt);
this._origin.add(tmpV1);
}
Expand Down Expand Up @@ -322,7 +332,8 @@ class MultiCamera extends BaseCamera {
right: false,
up: false,
down: false,
sprint: false
sprint: false,
crouch: false
};
}

Expand Down
14 changes: 1 addition & 13 deletions src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,7 @@ class Viewer {
camera.camera.requestSceneColorMap(true);

// create camera controls
this.controlCamera = new MultiCamera({
lookSensitity: 0.3,
lookDamping: 0.97,
moveDamping: 0.97,
mousePanSpeed: 0.25,
mobilePanSpeed: 0.025,
pinchSpeed: 0.00025,
wheelSpeed: 0.005,
zoomThreshold: 0.01,
zoomExp: 0.5,
moveSpeed: 2,
sprintSpeed: 4
});
this.controlCamera = new MultiCamera();
app.root.addChild(this.controlCamera.entity);
this.controlCamera.attach(camera);

Expand Down

0 comments on commit 6c7223c

Please sign in to comment.