-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 Merge version 3 development branch to main
Merge pull request #4 from ma1ted/development
- Loading branch information
Showing
6 changed files
with
173 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
{ | ||
"name": "charactercontroller", | ||
"version": "2.1.0", | ||
"description": "A first person character controller for the Three.js graphics library", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"lint": "eslint src/index.js", | ||
"format": "prettier --write src/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ma1ted/charactercontroller.git" | ||
}, | ||
"keywords": [ | ||
"threejs", | ||
"fps", | ||
"controller" | ||
], | ||
"author": "malted", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ma1ted/charactercontroller/issues" | ||
}, | ||
"homepage": "https://github.com/ma1ted/charactercontroller#readme", | ||
"devDependencies": { | ||
"eslint": "^8.16.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"prettier": "^2.6.2" | ||
}, | ||
"dependencies": { | ||
"three": "^0.141.0" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry-url" | ||
} | ||
"name": "charactercontroller", | ||
"version": "3.0.0", | ||
"description": "A first person character controller for the Three.js graphics library", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"lint": "eslint src", | ||
"format": "prettier --write src" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ma1ted/charactercontroller.git" | ||
}, | ||
"keywords": [ | ||
"threejs", | ||
"fps", | ||
"controller" | ||
], | ||
"author": "malted", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ma1ted/charactercontroller/issues" | ||
}, | ||
"homepage": "https://github.com/ma1ted/charactercontroller#readme", | ||
"devDependencies": { | ||
"eslint": "^8.16.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"prettier": "^2.6.2" | ||
}, | ||
"dependencies": { | ||
"three": "^0.141.0" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry-url" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function registerKeyEvents() { | ||
document.addEventListener("keydown", (e) => { | ||
this.keysDown[e.code] = true; | ||
}); | ||
document.addEventListener("keyup", (e) => { | ||
this.keysDown[e.code] = false; | ||
}); | ||
} | ||
|
||
export function registerMouseMoveEvent() { | ||
window.addEventListener("mousemove", (e) => { | ||
clearTimeout(this.cancelDriftTimeout); | ||
this.mouse.x = e.movementX; | ||
this.mouse.y = e.movementY; | ||
this.cancelDriftTimeout = setTimeout(() => { | ||
this.mouse.x = this.mouse.y = 0; | ||
}, 10); | ||
}); | ||
} | ||
|
||
export function checkInputs() { | ||
// Check scalar values | ||
Object.entries(this.inputMappings.scalar).forEach(([axisName, axisInfo]) => { | ||
this.inputs[axisName] = 0; | ||
axisInfo.forEach((axisInput) => { | ||
if (axisInput.inputs.some((code) => this.keysDown[code])) { | ||
this.inputs[axisName] += axisInput.value; | ||
} | ||
}); | ||
}); | ||
|
||
// Check discrete values | ||
Object.entries(this.inputMappings.discrete).forEach(([eventName, eventCodes]) => { | ||
this.inputs[eventName] = eventCodes.some((code) => this.keysDown[code]); | ||
}); | ||
} |
Oops, something went wrong.