@hology/core 0.0.110 → 0.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +0,0 @@
1
- import { ActionInput, AxisInput, RotationInput } from '../../../../../gameplay/input/index.js';
2
- import { PhysicsSystem } from '../../../../../gameplay/services/physics/physics-system.js';
3
- import { Vector3 } from "three";
4
- import { ActorComponent } from '../../../component.js';
5
- import { CharacterMovementMode } from './modes.js';
6
- export declare class CharacterMovementComponent extends ActorComponent {
7
- private physicsSystem;
8
- readonly directionInput: AxisInput;
9
- readonly jumpInput: ActionInput;
10
- readonly sprintInput: ActionInput;
11
- readonly rotationInput: RotationInput;
12
- horizontalSpeed: number;
13
- maxSpeed: number;
14
- maxSpeedBackwards: number;
15
- maxSpeedSprint: number;
16
- maxWalkingSlopeAngle: number;
17
- jumpVelocity: number;
18
- fallingMovementControl: number;
19
- fallingReorientation: boolean;
20
- gravityOverride: number;
21
- colliderHeight: number;
22
- colliderRadius: number;
23
- readonly velocity: Vector3;
24
- mode: CharacterMovementMode;
25
- isSprinting: boolean;
26
- pressedJump: boolean;
27
- private rayTestResult;
28
- constructor(physicsSystem: PhysicsSystem);
29
- onInit(): void | Promise<void>;
30
- private getWallDirection;
31
- private moveTo;
32
- getEffectiveGravity(): number;
33
- get isGrounded(): boolean;
34
- private createCollisionShape;
35
- private step;
36
- private performMovement;
37
- }
38
- //# sourceMappingURL=character-movement%20copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"character-movement copy.d.ts","sourceRoot":"","sources":["../../../../../../src/gameplay/actors/builtin/components/character/character-movement copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAiB,MAAM,4DAA4D,CAAC;AAE1G,OAAO,EAAS,OAAO,EAAa,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,cAAc,EAAa,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAMnD,qBACa,0BAA2B,SAAQ,cAAc;IA+B9C,OAAO,CAAC,aAAa;IA5BjC,QAAQ,CAAC,cAAc,YAAkB;IACzC,QAAQ,CAAC,SAAS,cAAoB;IACtC,QAAQ,CAAC,WAAW,cAAoB;IACxC,QAAQ,CAAC,aAAa,gBAAsB;IAGrC,eAAe,SAAI;IAGnB,QAAQ,SAAI;IACZ,iBAAiB,SAAI;IACrB,cAAc,SAAK;IACnB,oBAAoB,SAAK;IACzB,YAAY,SAAI;IAChB,sBAAsB,SAAK;IAC3B,oBAAoB,UAAQ;IAC5B,eAAe,EAAE,MAAM,CAAO;IAC9B,cAAc,EAAE,MAAM,CAAM;IAC5B,cAAc,EAAE,MAAM,CAAK;IAGlC,QAAQ,CAAC,QAAQ,UAAgB;IACjC,IAAI,wBAAgC;IACpC,WAAW,UAAQ;IACnB,WAAW,UAAQ;IAEnB,OAAO,CAAC,aAAa,CAAsB;gBAEvB,aAAa,EAAE,aAAa;IAEhD,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IA4K9B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,MAAM;IAKP,mBAAmB;IAI1B,IAAW,UAAU,YAEpB;IAED,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,IAAI;IA4BZ,OAAO,CAAC,eAAe;CAW1B"}
@@ -1,4 +0,0 @@
1
- import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as s,AxisInput as e,RotationInput as o}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{toDegrees as a}from"../../../../../utils/math.js";import{Vector3 as h,MathUtils as l}from"three";import{ActorComponent as c,Component as p}from"../../../component.js";import{CharacterMovementMode as y}from"./modes.js";import{CapsuleCollisionShape as m}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as d}from"rxjs";import{PhysicsBodyType as u}from"../../../../services/physics/physics-system.js";let g=class extends c{constructor(t){super(),this.physicsSystem=t,this.directionInput=new e,this.jumpInput=new s,this.sprintInput=new s,this.rotationInput=new o,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=10,this.maxWalkingSlopeAngle=70,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2.5,this.colliderRadius=.5,this.velocity=new h,this.mode=y.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r}onInit(){this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:u.kinematic}),this.rotationInput.rotation.copy(this.actor.rotation);let t=this.rotationInput.rotation.y;const i=new h,s=new h,e=new h,o=new h,n=new h;let c=0;this.physicsSystem.afterStep.pipe(d(this.disposed)).subscribe((r=>{this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated;let a=t-this.rotationInput.rotation.y;t=this.rotationInput.rotation.y,e.copy(this.actor.position),o.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const p=o.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed,m=o.clone().applyAxisAngle(new h(0,1,0),this.rotationInput.rotation.y);this.mode===y.walking&&(0!==m.length()?(c=Math.min(p,c),c=l.lerp(c,p,4*r)):c=0,n.copy(m).multiplyScalar(c),this.pressedJump&&(this.mode=y.falling,this.velocity.copy(n),this.velocity.y=this.jumpVelocity)),this.mode===y.falling&&(this.velocity.y+=r*this.getEffectiveGravity(),n.copy(this.velocity),n.add(m.clone().multiplyScalar(p*this.fallingMovementControl*r)),this.fallingReorientation&&n.applyAxisAngle(new h(0,1,0),-a)),s.copy(n).normalize(),i.copy(n),this.actor.rotation.y-=a;const d=this.actor.position.add(n.multiplyScalar(r));this.moveTo(d),f(),this.isGrounded?this.velocity.y<=0&&(this.mode=y.walking,this.velocity.y=0):(this.mode=y.falling,this.velocity.copy(i)),this.mode===y.walking&&v(r),x(r),this.horizontalSpeed=c}));const p=new h(0,1,0),m=new h(0,-.1,0),g=new h,S=new h,f=()=>{const t=this.colliderHeight+2*this.colliderRadius;this.physicsSystem.rayTest(g.addVectors(this.actor.position,p.set(0,t/4,0)),S.addVectors(this.actor.position,m),this.rayTestResult,{excludeActor:this.actor})},v=t=>{if(this.isGrounded){const s=Math.acos(this.rayTestResult.hitNormal.y),o=this.rayTestResult.hitPoint.y;if(a(s)<this.maxWalkingSlopeAngle){this.actor.position.y=o;const s=this.actor.position.sub(e).normalize().multiplyScalar(i.length()*t);this.moveTo(e.clone().add(s))}}},w=new r,x=t=>{const i=this.physicsSystem.getActorContacts(this.actor,s).filter((t=>a(Math.acos(-t.ni.y))>this.maxWalkingSlopeAngle));if(i.length>0){if(i[0].ni.clone().dot(s)<=0)return;this.moveTo(e);const o=i[0].rj.clone(),n=this.getWallDirection(i[0].ni,s);if(!this.physicsSystem.rayTest(o,n.clone().multiplyScalar(this.colliderRadius).add(o),w,{debugColor:0}).hasHit){const i=s.dot(n),e=n.multiplyScalar(this.horizontalSpeed*i);e.y+=this.velocity.y,e.multiplyScalar(t);const o=this.actor.position.clone().add(e);this.moveTo(o)}}}}getWallDirection(t,i){const s=t.clone().negate().cross(new h(0,1,0));return s.dot(i)<0?s.negate():s}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}get isGrounded(){return this.rayTestResult.hasHit}createCollisionShape(){const t=new m(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2,t}step(t){}performMovement(t){}};g=t([p(),i("design:paramtypes",[n])],g);export{g as CharacterMovementComponent};/*
2
- * Copyright (©) 2023. All rights reserved.
3
- * See the LICENSE.md file for details.
4
- */