finish events
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import * as THREE from 'three'
|
||||
|
||||
export const CONTROLLER_BODY_RADIUS = 0.28;
|
||||
import { QueryFilterFlags } from '@dimforge/rapier3d';
|
||||
|
||||
export class CharacterControls {
|
||||
|
||||
@@ -33,7 +32,7 @@ export class CharacterControls {
|
||||
// // Automatically slide down on slopes smaller than 30 degrees.
|
||||
// this.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180);
|
||||
// this.characterController.enableAutostep(0.5, 0.2, true);
|
||||
// this.characterController.setApplyImpulsesToDynamicBodies(true);
|
||||
this.characterController.setApplyImpulsesToDynamicBodies(true);
|
||||
// this.characterController.setCharacterMass(50);
|
||||
this.po = po;
|
||||
this.pointerControls = pointerControls
|
||||
@@ -47,20 +46,14 @@ export class CharacterControls {
|
||||
this.actionStart = 0;
|
||||
this.cameraDelta = 0;
|
||||
this.cameraIdleDelta = 0;
|
||||
//this.toggleRun = true
|
||||
}
|
||||
|
||||
switchRunToggle() {
|
||||
this.toggleRun = !this.toggleRun
|
||||
}
|
||||
|
||||
update(world, delta, pointerControls) {
|
||||
const directionPressed = pointerControls.moving
|
||||
let input = this.getInput(pointerControls)
|
||||
|
||||
let play = this.currentAction || 'idle', velocity = this.walkVelocity;
|
||||
this.fadeDuration = 0.2;
|
||||
if (input[1] && this.toggleRun) {
|
||||
if (input[1] && pointerControls.running) {
|
||||
play = 'run';
|
||||
velocity = this.runVelocity
|
||||
} else if (input[1] > 0) {
|
||||
@@ -111,23 +104,13 @@ export class CharacterControls {
|
||||
|
||||
this.walkDirection.x = this.walkDirection.y = this.walkDirection.z = 0
|
||||
|
||||
if (directionPressed) {
|
||||
if (pointerControls.motion) {
|
||||
this.directionVelocity = this.directionVelocity * 2.5 * Math.abs(input[0])
|
||||
this.direction += input[0] * delta * 2.5 //this.directionVelocity;
|
||||
this.model.rotation.y = this.direction;
|
||||
this.walkDirection.set(0, 0, input[1])
|
||||
this.walkDirection.applyAxisAngle(this.rotateAngle, this.direction)
|
||||
this.walkDirection.normalize();
|
||||
|
||||
|
||||
//let dst = Math.sqrt(Math.pow(cameraPosition.x - this.model.position.x, 2) + Math.pow(cameraPosition.z - this.model.position.z, 2));
|
||||
//cameraPosition.y = 8 - dst;
|
||||
//if (dst >0.52){
|
||||
//}
|
||||
//this.camera.zoom = dst
|
||||
//this.camera.updateProjectionMatrix();
|
||||
|
||||
// run/walk velocity
|
||||
}
|
||||
|
||||
this.walkDirection.x = this.walkDirection.x * velocity * delta// + this.model.position.x
|
||||
@@ -138,8 +121,15 @@ export class CharacterControls {
|
||||
this.characterController.computeColliderMovement(
|
||||
this.po.collider, // The collider we would like to move.
|
||||
this.walkDirection, // The movement we would like to apply if there wasn’t any obstacle.
|
||||
QueryFilterFlags['EXCLUDE_SENSORS']
|
||||
);
|
||||
|
||||
// for (let i = 0; i < this.characterController.numComputedCollisions(); i++) {
|
||||
// let collision = this.characterController.computedCollision(i);
|
||||
// //console.log(collision)
|
||||
// // Do something with that collision information.
|
||||
// }
|
||||
|
||||
let correctedMovement = this.characterController.computedMovement();
|
||||
|
||||
let v = new THREE.Vector3();
|
||||
|
||||
Reference in New Issue
Block a user