@hology/core 0.0.62 → 0.0.63
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as e,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as u}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import{RootMotionClip as
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as e,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as u}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import g from"@dimforge/rapier3d-compat";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion.js";import*as S from"three";const v=new c,w=new c,A=1/30;let M=class extends h{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}constructor(t){super(),this.physicsSystem=t,this.directionInput=new o,this.jumpInput=new e,this.sprintInput=new e,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.velocity=new c,this.mode=m.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1;const i=this.cc=this.physicsSystem.getCharacterController(.1);i.enableSnapToGround(.1),i.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:y.kinematicVelocityBased,continousCollisionDetection:!1,friction:1,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation);let i=this.rotationInput.rotation.y;const e=new c,o=new c,s=new c,n=new c,r=new c,l=new c;let h=0,p=null;const d=new c,g=new c,M=new c,T=new c;this.physicsSystem.beforeStep.pipe(u(this.disposed)).subscribe((u=>{if(this.checkGrounded(u),null!=this.rootMotionAction){if(this.rootMotionAction.getClip()instanceof f){const t=this.rootMotionInterpolant;this.resetRootMotion&&(d.fromArray(t.evaluate(0)),this.resetRootMotion=!1),T.fromArray(t.evaluate(this.rootMotionAction.time)),g.subVectors(T,d),d.copy(T),this.rootMotionAction.getRoot().getWorldScale(M),g.multiply(M)}}u>A&&(u=A);const y=null!=this.rootMotionAction&&this.rootMotionAction.enabled&&0!=g.length();this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated&&this.directionInput.vertical>=0;let b=i-this.rotationInput.rotation.y;i=this.rotationInput.rotation.y,s.copy(this.actor.position),n.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const C=n.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;if(l.copy(n).applyAxisAngle(x,this.rotationInput.rotation.y),this.mode===m.walking?(0!==l.length()?(h=Math.min(C,h),h=a.lerp(h,C,4*u)):h=0,r.copy(l).multiplyScalar(h),this.pressedJump&&(this.mode=m.falling,this.velocity.copy(r),this.velocity.y=this.jumpVelocity),r.y=.016*this.getEffectiveGravity()):this.mode===m.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=m.falling,this.velocity.copy(r),this.velocity.y=this.jumpVelocity),this.velocity.y+=u*this.getEffectiveGravity(),r.copy(this.velocity),r.add(l.clone().multiplyScalar(C*this.fallingMovementControl*u)),this.fallingReorientation&&r.applyAxisAngle(new c(0,1,0),-b)),o.copy(r).normalize(),e.copy(r),this.actor.rotation.y-=b,r.length(),y?(g.applyAxisAngle(x,this.actor.rotation.y),g.y+=u*this.getEffectiveGravity(),v.copy(g)):v.copy(r).multiplyScalar(u),this.isGrounded&&this.mode===m.walking&&(this.rayTestResult.distance>t.offset()||(v.y=0),this.physicsSystem.getActorComputedMovement(this.actor,t,v),t.computedCollision(0,G),null!=G&&null!=G.normal1)){const i=(new S.Vector3).copy(G.normal1);Math.acos(i.dot(x))>t.maxSlopeClimbAngle()&&(v.y=.016*this.getEffectiveGravity()*.5)}w.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,v)),this.physicsSystem.setLinearVelocity(this.actor,w.divideScalar(u));let j=function(t){if(t.numComputedCollisions()>0){const i=t.computedCollision(0);I.x=i.normal2.x,I.y=i.normal2.y,I.z=i.normal2.z;const e=I.angleTo(x);I.x=i.normal1.x,I.y=i.normal1.y,I.z=i.normal1.z;const o=I.angleTo(x);return!(e<100)&&o>t.minSlopeSlideAngle()}return!1}(t);y||this.isGrounded&&!j||this.mode!==m.falling&&(null==p?p=performance.now():performance.now()-p>100&&(this.mode=m.falling,this.velocity.copy(e))),this.isGrounded&&this.velocity.y<=0&&(this.mode,m.falling,this.mode=m.walking,this.velocity.y=0,p=null),this.mode,m.walking,this.horizontalSpeed=h}))}debugDirection(){const t=new l(v,this.actor.position,1,65280);this.actor.object.parent.add(t),setTimeout((()=>{t.removeFromParent()}),30);const i=new l(w,this.actor.position,1,16711680);this.actor.object.parent.add(i),setTimeout((()=>{i.removeFromParent()}),30)}setRootMotionAction(t){const i=t?.getClip();if(i instanceof f){this.rootMotionAction=t,this.resetRootMotion=!0;const e=[];this.rootMotionInterpolant=i.motionTrack.InterpolantFactoryMethodSmooth(e)}}getWallDirection(t,i){const e=t.clone().negate().cross(x);return e.dot(i)<0?e.negate():e}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}checkGrounded(t){this.colliderHeight,this.colliderRadius;j.y=-.05,this.physicsSystem.rayTest(T.addVectors(this.actor.position,C.set(0,this.offset,0)),b.addVectors(this.actor.position,j),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}get isGrounded(){return this.rayTestResult.hasHit||this.cc.computedGrounded()}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2+this.offset,t}step(t){}performMovement(t){}};M=t([p({inEditor:!1}),i("design:paramtypes",[n])],M);export{M as CharacterMovementComponent};const x=new c(0,1,0),I=new c;const T=new c,b=new c,C=new c(0,1,0),j=new c(0,-.1,0),G=(new c(0,-1,0),new g.CharacterCollision);
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|