PlayerControls
PlayerControls copied to clipboard
Three.js 3rd person player controls
PlayerControls
PlayerControls is a modificatin to the three.js script, OrbitControls.js: https://gist.github.com/mrflix/8351020
PlayerControls enables quick and easy access to a 3rd person player controller:
- "import" three.js library
<script src="js/three.js"></script>
- "import" PlayerControls.js
<script src="js/PlayerControls.js"></script>
- instantiate PlayerControls object ( pass camera and player object as arguments )
var controls = new THREE.PlayerControls( camera , player );
Keep in mind that player is a mesh or group object with position.x, position.y, etc.. properties
- update controls in animate function
function animate() {
requestAnimationFrame( animate );
// other things you do..
controls.update();
render();
}
You can adjust the speed of the player with:
controls.moveSpeed = some_number;
You can adjust the turn speed with:
controls.turnSpeed = some_number;