{"id":20582812,"url":"https://github.com/malted/charactercontroller","last_synced_at":"2025-04-14T20:16:28.103Z","repository":{"id":38412396,"uuid":"499637325","full_name":"malted/charactercontroller","owner":"malted","description":"A first person character controller for the Three.js graphics library","archived":false,"fork":false,"pushed_at":"2022-12-18T00:13:13.000Z","size":100,"stargazers_count":16,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-14T20:16:21.875Z","etag":null,"topics":["charactercontroller","controller","first-person","fps","threejs"],"latest_commit_sha":null,"homepage":"https://controller.malted.dev","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malted.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-03T20:05:48.000Z","updated_at":"2024-12-22T16:45:42.000Z","dependencies_parsed_at":"2023-01-29T18:10:13.121Z","dependency_job_id":null,"html_url":"https://github.com/malted/charactercontroller","commit_stats":null,"previous_names":["malted/charactercontroller","ma1ted/charactercontroller"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fcharactercontroller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fcharactercontroller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fcharactercontroller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fcharactercontroller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malted","download_url":"https://codeload.github.com/malted/charactercontroller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952357,"owners_count":21188427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charactercontroller","controller","first-person","fps","threejs"],"created_at":"2024-11-16T06:37:11.229Z","updated_at":"2025-04-14T20:16:28.083Z","avatar_url":"https://github.com/malted.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# charactercontroller\n\nA first person character controller for the Three.js graphics library\n\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/charactercontroller)\n![npm](https://img.shields.io/npm/v/charactercontroller)\n![NPM](https://img.shields.io/npm/l/charactercontroller)\n\n## [Demo](https://controller.malted.dev)\n\n## Installation\n\n`npm install charactercontroller`\n\n## Usage\n\n```javascript\nimport CharacterController from \"charactercontroller\";\n\n// Scene \u0026 renderer initialisation...\n\nconst controller = new CharacterController(scene, options);\n\nfunction animate() {\n\trequestAnimationFrame(animate);\n\t// ...\n\tcontroller.update();\n\trenderer.render(scene, controller.camera);\n}\n```\n\n- `scene`\n\t\u003e An instance of `THREE.Scene` that the Character Controller is to become a child of.\n\n- `options`\n\t\u003e An object defining options for the Character Controller. The valid fields are described below\n\n## Constructor Options\n\n- `walkSpeed`\n\t\u003e The rate at which the controller is translated in the scene in response to player inputs, when the sprint key (left shift) **is not** being pressed.\n\t- Default: `5`\n\n- `sprintSpeed`\n\t\u003e The rate at which the controller is translated in the scene in response to player inputs, when the sprint key (left shift) **is** being pressed.\n  - Default: `10`\n\n- `floorDistance`\n\t\u003e How far above a surface the controller can get before stopping falling.\n\t\u003e \n\t\u003e Could be interpreted as the height of the player.\n\t- Default: `1`\n\n- `gravity`\n\t\u003e How quickly the controller is pulled down when there is no surface beneath it.\n\t- Default: `-9.81`\n\n- `jumpPower`\n\t\u003e With how much force the controller is projected upwards when a jump is initiated.\n\t- Default: `5`\n\n- `sensitivity`\n\t- `x`\n\n\t\t\u003e How much the camera should move in response to the player moving the mouse left and right.\n\t\t- Default: `0.1`\n\t- `y`\n\t\t\u003e How much the camera should move in response to the player moving the mouse up and down.\n    \t- Default: `0.1`\n- `lookLimit`\n\t- `down`\n\t\n\t\t\u003e The angle in degrees that the camera's `x` rotation should be clamped to when looking down\n\t\t- Default: `0`\n\t- `up`\n\t\n\t\t\u003e The angle in degrees that the camera's `x` rotation should be clamped to when looking up\n  \t\t- Default: `180`\n \n- `cameraFov`\n\t\u003e The field of view of the camera attatched to the character controller.\n\t- Default: `75`\n\n- `inputMappings`\n\t\u003e The `KeyboardEvent.code`s that control the character controller. An array of `code`s are used to support multiple keys controlling the same actions; primarily for accessability reasons.\n\n\t- `scalar`\n \n\t\t\u003e **Note**\n\t\t\u003e \n    \t\u003e The scalar property defines axes that can take on any value within a range. There are two axes that control the planar movement of the character controller; horizontal and vertical, named `horizontalAxis` and `verticalAxis` respectively. These both take an array of input maps as values.\n    \t\u003e The format of the input maps required in arrays on scalar axes is as follows;\n    \t\u003e \n    \t\u003e `{ inputs: KeyboardEvent.code[], value: number }`\n    \t\u003e \n    \t\u003e Where `value` is \tthe magnitude of the axis when a key in `inputs` is being pressed.\n\n\t\t+ `horizontalAxis`\n\t\t\t- Default:\n    \t\t\t```js\n    \t\t\t{ inputs: [\"KeyA\", \"ArrowLeft\"], value: -1 },\n\t\t\t\t{ inputs: [\"KeyD\", \"ArrowRight\"], value: 1 },\n\t\t\t\t```\n    \t+ `verticalAxis`\n    \t\t- Default: \n\t\t\t\t```js\n \t\t\t\t{ inputs: [\"KeyS\", \"ArrowDown\"], value: -1 },\n\t\t\t\t{ inputs: [\"KeyW\", \"ArrowUp\"], value: 1 },\n\t\t\t\t```\n\t- `discrete`\n\n\t\t\u003e **Note**\n\t\t\u003e\n\t\t\u003e The discrete property defines single-fire actions that occur at a specific point in time. These inputs differ from the ones defined under `scalar` as they describe events that happen once at a time, rather than continuously over time. The format of input maps required here is simply an array of `KeyboardEvent.code`s.\n    \t+ `jump`\n      \t\t- Default: `[\"Space\"]`\n    \t+ `sprint`\n      \t\t- Default: `[\"ShiftLeft\", \"ShiftRight\"]`,\n\t\u003cbr /\u003e\n\t\n\t\u003e **Note**\n\t\u003e\n\t\u003e The default `inputMappings` object is shown below;\n\t```js\n\tinputMappings = {\n\t\tscalar: {\n\t\t\thorizontalAxis: [\n\t\t\t\t{ inputs: [\"KeyA\", \"ArrowLeft\"], value: -1 },\n\t\t\t\t{ inputs: [\"KeyD\", \"ArrowRight\"], value: 1 },\n\t\t\t],\n\t\t\tverticalAxis: [\n\t\t\t\t{ inputs: [\"KeyS\", \"ArrowDown\"], value: -1 },\n\t\t\t\t{ inputs: [\"KeyW\", \"ArrowUp\"], value: 1 },\n\t\t\t],\n\t\t},\n\t\tdiscrete: {\n\t\t\tjump: [\"Space\"],\n\t\t\tsprint: [\"ShiftLeft\", \"ShiftRight\"],\n\t\t},\n\t},\n\t```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalted%2Fcharactercontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalted%2Fcharactercontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalted%2Fcharactercontroller/lists"}