intermediate
This commit is contained in:
+3
-91
@@ -15,12 +15,6 @@ class Hero{
|
||||
|
||||
init(gameEngine){
|
||||
this.gameEngine = gameEngine;
|
||||
//this.gameEngine.orbitControls.object = this.model;
|
||||
//this.gameEngine.orbitControls.target = this.model.position;
|
||||
|
||||
//this.gameEngine.orbitControls.enabled = false;
|
||||
|
||||
//this.model.add(gameEngine.camera)
|
||||
gameEngine.camera.position.set(0,17,-30)
|
||||
gameEngine.camera.lookAt(new THREE.Vector3(this.model.position.x, 5, this.model.position.z))
|
||||
|
||||
@@ -36,84 +30,17 @@ class Hero{
|
||||
this.animationsMap[a.name] = this.mixer.clipAction(a);
|
||||
})
|
||||
|
||||
// this.actionWalk = this.mixer.clipAction( this.object.animations.find(a=>a.name=='walk') );
|
||||
// this.actionIdle = this.mixer.clipAction( this.object.animations.find(a=>a.name=='idle') );
|
||||
// this.actionIdle.play();
|
||||
// this.activeAction = this.actionIdle;
|
||||
this.pointerControls = new PointerControls(gameEngine.camera, this.model, gameEngine.renderer.domElement);
|
||||
gameEngine.hero = this;
|
||||
|
||||
// Character Collider
|
||||
// const characterCollider = new THREE.Object3D()
|
||||
// characterCollider.position.y = 3
|
||||
// gameEngine.activeObjects.add(characterCollider)
|
||||
|
||||
|
||||
// const colliderShape = new CANNON.Sphere(0.5)
|
||||
// const colliderBody = new CANNON.Body({ mass: 1, material: gameEngine.phy.slipperyMaterial })
|
||||
// colliderBody.addShape(colliderShape, new CANNON.Vec3(0, 0.5, 0))
|
||||
// colliderBody.addShape(colliderShape, new CANNON.Vec3(0, -0.5, 0))
|
||||
// colliderBody.position.set(
|
||||
// characterCollider.position.x,
|
||||
// characterCollider.position.y,
|
||||
// characterCollider.position.z
|
||||
// )
|
||||
// colliderBody.linearDamping = 0.95
|
||||
// colliderBody.angularFactor.set(0, 1, 0) // prevents rotation X,Z axis
|
||||
// //colliderBody.sleepSpeedLimit = 1.0;
|
||||
// gameEngine.phy.world.addBody(colliderBody)
|
||||
|
||||
let po = gameEngine.phy.add(this.model, 'kinematicPositionBased', false, undefined, 'ball', { radius: 0.28})
|
||||
|
||||
// let bodyDesc = RAPIER.RigidBodyDesc.kinematicPositionBased().setTranslation(
|
||||
// // characterCollider.position.x,
|
||||
// // characterCollider.position.y,
|
||||
// // characterCollider.position.z
|
||||
// -1, 3, 1
|
||||
// )
|
||||
// let rigidBody = gameEngine.phy.world.createRigidBody(bodyDesc);
|
||||
// let dynamicCollider = RAPIER.ColliderDesc.ball(0.28);
|
||||
// gameEngine.phy.world.createCollider(dynamicCollider, rigidBody.handle);
|
||||
let po = gameEngine.phy.add(this.model, 'kinematicPositionBased', false, undefined, 'capsule', { radius: 0.5, halfHeight: 1})
|
||||
po.collider.setTranslationWrtParent({ x: 0, y: 2.0, z: 0 });
|
||||
|
||||
this.characterControls = new CharacterControls(this.model, this.mixer,
|
||||
this.animationsMap, gameEngine.orbitControls, gameEngine.camera, 'idle',
|
||||
new RAPIER.Ray(
|
||||
{ x: 0, y: 0, z: 0 },
|
||||
{ x: 0, y: -1, z: 0}
|
||||
), po.rigidBody, this.pointerControls)
|
||||
|
||||
// this.characterCollider = characterCollider;
|
||||
// this.colliderBody = colliderBody;
|
||||
this.animationsMap, gameEngine, 'idle', po, this.pointerControls)
|
||||
|
||||
this.clock = new THREE.Clock()
|
||||
this.delta = 0
|
||||
// this.inputVelocity = new THREE.Vector3()
|
||||
// this.velocity = new CANNON.Vec3()
|
||||
// this.quat = new THREE.Quaternion()
|
||||
// this.v = new THREE.Vector3()
|
||||
// this.rotation = new THREE.Euler()
|
||||
// this.targetQuaternion = new THREE.Quaternion()
|
||||
// this.distance = 0
|
||||
// this.canJump = true;
|
||||
|
||||
// this.contactNormal = new CANNON.Vec3()
|
||||
// this.upAxis = new CANNON.Vec3(0, 1, 0)
|
||||
|
||||
// colliderBody.addEventListener('collide', function (e) {
|
||||
// const contact = e.contact
|
||||
// if (contact.bi.id == this.colliderBody.id) {
|
||||
// contact.ni.negate(this.contactNormal)
|
||||
// } else {
|
||||
// this.contactNormal.copy(contact.ni)
|
||||
// }
|
||||
// if (this.contactNormal.dot(this.upAxis) > 0.5) {
|
||||
// if (!this.canJump) {
|
||||
// setAction(animationActions[1], true)
|
||||
// }
|
||||
// this.canJump = true
|
||||
// }
|
||||
// }.bind(this))
|
||||
|
||||
|
||||
this.ready = true;
|
||||
}
|
||||
@@ -122,21 +49,6 @@ class Hero{
|
||||
this.pointerControls.controls.lock();
|
||||
}
|
||||
|
||||
// setAction(toAction, loop){
|
||||
// if (toAction != this.activeAction) {
|
||||
// let lastAction = this.activeAction;
|
||||
// this.activeAction = toAction
|
||||
// lastAction.fadeOut(0.1)
|
||||
// this.activeAction.reset()
|
||||
// this.activeAction.fadeIn(0.1)
|
||||
// this.activeAction.play()
|
||||
// if (!loop) {
|
||||
// this.activeAction.clampWhenFinished = true
|
||||
// this.activeAction.loop = THREE.LoopOnce
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
update(){
|
||||
//return
|
||||
if (this.gameEngine.renderer.xr.isPresenting) return;
|
||||
|
||||
Reference in New Issue
Block a user