diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 1a70b62a..b7c45564 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -45,6 +45,7 @@ export default defineConfig({ { text: 'OrbitControls', link: '/guide/controls/orbit-controls' }, { text: 'TransformControls', link: '/guide/controls/transform-controls' }, { text: 'PointerLockControls', link: '/guide/controls/pointer-lock-controls' }, + { text: 'KeyboardControls', link: '/guide/controls/keyboard-controls' }, { text: 'MapControls', link: '/guide/controls/map-controls' }, ], }, diff --git a/docs/guide/controls/keyboard-controls.md b/docs/guide/controls/keyboard-controls.md new file mode 100644 index 00000000..a84ed8c7 --- /dev/null +++ b/docs/guide/controls/keyboard-controls.md @@ -0,0 +1,61 @@ +# KeyboardControls + +KeyboardControls is a special type of controller that allows you to move using your keyboard. + +## In combination with PointerLockControls. + +Here you need to use the PointerLockControls with make-default props, KeyboardControls will automatically adapt to it, creating a really good effect first player experiences. + +```vue{3} + +``` + +Just by doing this, works great but in addition the TresJs team give some special props (only available with this mode) to create more realistic sensation + +- headBobbing: To simulate the walk balance of the head +- Jump: to jump +- gravity: to control the gravity related to the jump + +## In combination with slots. + +Here you can move meshes by using your keyboard, by default you move through the X and Z axis, but you can change it with the is2D prop, to move your meshes on the X and Y axis + +```vue{3} + +``` + +::: warning +Is really important that the Perspective camera is set first in the canvas. Otherwise might break. +::: + +## Props + +| Prop | Description | Default | +| :-------------- | :-------------------------------------------------------------------------------------------- | ---------- | +| **forward** | Keys to go forward. | ['w', 'W'] | +| **back** | Keys to go back. | ['s', 'S'] | +| **left** | Keys to go left. | ['a', 'A'] | +| **right** | Keys to go right. | ['d', 'D'] | +| **headBobbing** | Indicates if the forward movement is in the Z axis or Y axis. (only with PointerLockControls) | false | +| **jump** | Key to jump (only with PointerLockControls). | [' '] | +| **gravity** | Default gravity number for jump. | 9.8 | +| **moveSpeed** | Speed movement | 0.1 | +| **is2D** | Indicates if the forward movement is in the Z axis or Y axis. (only for meshes) | false | diff --git a/playground/src/components/PointerLockControlsDemo.vue b/playground/src/components/PointerLockControlsDemo.vue index b9fdd94a..4e60fe0f 100644 --- a/playground/src/components/PointerLockControlsDemo.vue +++ b/playground/src/components/PointerLockControlsDemo.vue @@ -1,26 +1,27 @@