aaaaaaaaaa
This commit is contained in:
parent
8c509ab561
commit
51fb57b557
|
@ -149,8 +149,10 @@ export class ThirdPersonCamera {
|
||||||
// https://www.youtube.com/watch?v=UuNPHOJ_V5o
|
// https://www.youtube.com/watch?v=UuNPHOJ_V5o
|
||||||
const factor = 1.0 - Math.pow(0.001, dt);
|
const factor = 1.0 - Math.pow(0.001, dt);
|
||||||
|
|
||||||
this.currentPosition.lerp(offset, factor);
|
// this.currentPosition.lerp(offset, factor);
|
||||||
this.currentLookAt.lerp(lookAt, factor);
|
// this.currentLookAt.lerp(lookAt, factor);
|
||||||
|
this.currentPosition.copy(offset);
|
||||||
|
this.currentLookAt.copy(lookAt);
|
||||||
|
|
||||||
this.camera.position.copy(this.currentPosition);
|
this.camera.position.copy(this.currentPosition);
|
||||||
this.camera.lookAt(this.currentLookAt);
|
this.camera.lookAt(this.currentLookAt);
|
||||||
|
|
|
@ -24,9 +24,9 @@ export class Game extends Engine {
|
||||||
this.use(ViewportComponent);
|
this.use(ViewportComponent);
|
||||||
this.use(EnvironmentComponent);
|
this.use(EnvironmentComponent);
|
||||||
this.use(LevelComponent);
|
this.use(LevelComponent);
|
||||||
this.use(GameplayComponent);
|
|
||||||
this.use(MouseComponent);
|
this.use(MouseComponent);
|
||||||
this.use(PhysicsWorldComponent);
|
this.use(PhysicsWorldComponent);
|
||||||
|
this.use(GameplayComponent);
|
||||||
|
|
||||||
this.getComponent(ViewportComponent).setSizeFromViewport();
|
this.getComponent(ViewportComponent).setSizeFromViewport();
|
||||||
this.start();
|
this.start();
|
||||||
|
|
|
@ -55,11 +55,11 @@ export class GameplayComponent extends EngineComponent {
|
||||||
this.cleanUpEvents = this.bindEvents();
|
this.cleanUpEvents = this.bindEvents();
|
||||||
this.server.track(this.world);
|
this.server.track(this.world);
|
||||||
this.server.connect('ws://localhost:8256', this.uuid, 'testing');
|
this.server.connect('ws://localhost:8256', this.uuid, 'testing');
|
||||||
|
// this.loadCharacter('test', undefined, undefined, this.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
override update(delta: number): void {
|
override update(delta: number): void {
|
||||||
this.controls?.update(delta);
|
this.controls?.update(delta);
|
||||||
|
|
||||||
this.move.set(0, 0, 0);
|
this.move.set(0, 0, 0);
|
||||||
this.look.setFromMatrixColumn(this.renderer.camera.matrix, 0);
|
this.look.setFromMatrixColumn(this.renderer.camera.matrix, 0);
|
||||||
this.look.multiplyScalar(this.movement.forward + -this.movement.backward);
|
this.look.multiplyScalar(this.movement.forward + -this.movement.backward);
|
||||||
|
@ -83,7 +83,6 @@ export class GameplayComponent extends EngineComponent {
|
||||||
jump,
|
jump,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.character?.setVelocity(this.move);
|
this.character?.setVelocity(this.move);
|
||||||
|
|
||||||
if (this.move.length()) {
|
if (this.move.length()) {
|
||||||
|
@ -119,7 +118,7 @@ export class GameplayComponent extends EngineComponent {
|
||||||
|
|
||||||
this.world.add(char);
|
this.world.add(char);
|
||||||
|
|
||||||
if (rot) char.quaternion.copy(rot);
|
if (rot) char.applyQuaternion(rot);
|
||||||
|
|
||||||
this.events.emit('sceneJoin', char);
|
this.events.emit('sceneJoin', char);
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ export class PhysicsWorldComponent extends EngineComponent {
|
||||||
update(delta: number): void {
|
update(delta: number): void {
|
||||||
if (!this.physicsWorld) return;
|
if (!this.physicsWorld) return;
|
||||||
// FIXME: physics is tied to the FPS
|
// FIXME: physics is tied to the FPS
|
||||||
|
this.physicsWorld.timestep = delta;
|
||||||
this.physicsWorld?.step();
|
this.physicsWorld?.step();
|
||||||
for (const object of this.trackedObjects) object.tickPhysics(delta);
|
for (const object of this.trackedObjects) object.tickPhysics(delta);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +45,7 @@ export class PhysicsWorldComponent extends EngineComponent {
|
||||||
const gravity = new Vector3(0, this.world.gravity, 0);
|
const gravity = new Vector3(0, this.world.gravity, 0);
|
||||||
const world = new physicsEngine.World(gravity);
|
const world = new physicsEngine.World(gravity);
|
||||||
this.physicsWorld = world;
|
this.physicsWorld = world;
|
||||||
this.physicsWorld.timestep = 0.016;
|
this.physicsWorld.timestep = 1 / 60;
|
||||||
this.physicsEngine = physicsEngine;
|
this.physicsEngine = physicsEngine;
|
||||||
this.initializePhysicsScene();
|
this.initializePhysicsScene();
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
AnimationClip,
|
AnimationClip,
|
||||||
AnimationMixer,
|
AnimationMixer,
|
||||||
LoopOnce,
|
LoopOnce,
|
||||||
|
Matrix4,
|
||||||
Quaternion,
|
Quaternion,
|
||||||
Skeleton,
|
Skeleton,
|
||||||
SkinnedMesh,
|
SkinnedMesh,
|
||||||
|
@ -27,6 +28,7 @@ export class Humanoid extends GameObject implements PhysicsTicking {
|
||||||
private _health = 100;
|
private _health = 100;
|
||||||
private _maxHealth = 100;
|
private _maxHealth = 100;
|
||||||
private _velocity = new Vector3(0, 0, 0);
|
private _velocity = new Vector3(0, 0, 0);
|
||||||
|
private _serverSet = false;
|
||||||
private _serverVelocity = new Vector3(0, 0, 0);
|
private _serverVelocity = new Vector3(0, 0, 0);
|
||||||
private _serverPosition = new Vector3(0, 0, 0);
|
private _serverPosition = new Vector3(0, 0, 0);
|
||||||
private _serverRotation = new Quaternion();
|
private _serverRotation = new Quaternion();
|
||||||
|
@ -214,10 +216,16 @@ export class Humanoid extends GameObject implements PhysicsTicking {
|
||||||
this._appliedGravity.y = 0;
|
this._appliedGravity.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._serverSet) {
|
||||||
|
this.rigidBody!.setRotation(this._serverRotation, false);
|
||||||
|
this.rigidBody!.setTranslation(this._serverPosition, false);
|
||||||
|
this._serverSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Apply rigidbody transforms to object from last process tick
|
// Apply rigidbody transforms to object from last process tick
|
||||||
if (this.rigidBody) {
|
if (this.rigidBody) {
|
||||||
this.parent!.position.copy(this.rigidBody.translation() as any);
|
this.parent!.position.copy(this.rigidBody.translation() as any);
|
||||||
this.parent!.quaternion.copy(this.rigidBody.rotation() as any);
|
this.parent?.quaternion.copy(this.rigidBody.rotation() as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run animation
|
// Run animation
|
||||||
|
@ -238,12 +246,17 @@ export class Humanoid extends GameObject implements PhysicsTicking {
|
||||||
this._velocity.clone().add(this._appliedGravity).multiplyScalar(dt)
|
this._velocity.clone().add(this._appliedGravity).multiplyScalar(dt)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Apply look vector
|
// Apply look direction to the physics engine
|
||||||
this._currentLookAt.copy(this.parent!.position);
|
const sink = new Vector3();
|
||||||
this._currentLookAt.add(this._lookAt);
|
const rotQuat = new Quaternion();
|
||||||
this.parent?.lookAt(this._currentLookAt);
|
new Matrix4()
|
||||||
|
.lookAt(
|
||||||
this.applyRotation(this.parent!.quaternion);
|
this.parent!.position,
|
||||||
|
this.parent!.position.clone().sub(this._lookAt),
|
||||||
|
new Vector3(0, 1, 0)
|
||||||
|
)
|
||||||
|
.decompose(sink, rotQuat, sink);
|
||||||
|
this.rigidBody?.setRotation(rotQuat, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
setWalkAnimationState(index: number) {
|
setWalkAnimationState(index: number) {
|
||||||
|
@ -286,9 +299,10 @@ export class Humanoid extends GameObject implements PhysicsTicking {
|
||||||
|
|
||||||
synchronize(event: ServerTransformEvent) {
|
synchronize(event: ServerTransformEvent) {
|
||||||
if (!this.rigidBody) return;
|
if (!this.rigidBody) return;
|
||||||
this._serverPosition.copy(event.position);
|
|
||||||
this._serverRotation.copy(event.quaternion);
|
this._serverRotation.copy(event.quaternion);
|
||||||
|
this._serverPosition.copy(event.position);
|
||||||
this._serverVelocity.copy(event.velocity);
|
this._serverVelocity.copy(event.velocity);
|
||||||
|
this._serverSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createNameTag() {
|
private createNameTag() {
|
||||||
|
@ -313,7 +327,7 @@ export class Humanoid extends GameObject implements PhysicsTicking {
|
||||||
const grounded = this.characterControllerRef.computedGrounded();
|
const grounded = this.characterControllerRef.computedGrounded();
|
||||||
vec3.copy(computed as Vector3);
|
vec3.copy(computed as Vector3);
|
||||||
vec3.add(this.parent.position);
|
vec3.add(this.parent.position);
|
||||||
vec3.lerp(this._serverPosition, 0.05);
|
// vec3.lerp(this._serverPosition, 0.05);
|
||||||
this.rigidBody?.setNextKinematicTranslation(vec3);
|
this.rigidBody?.setNextKinematicTranslation(vec3);
|
||||||
|
|
||||||
// After the collider movement calculation is done, we can read the
|
// After the collider movement calculation is done, we can read the
|
||||||
|
@ -327,11 +341,6 @@ export class Humanoid extends GameObject implements PhysicsTicking {
|
||||||
this._grounded = grounded;
|
this._grounded = grounded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private applyRotation(quat: Quaternion) {
|
|
||||||
quat.slerp(this._serverRotation, 0.05);
|
|
||||||
this.rigidBody?.setRotation(quat, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose(): void {
|
dispose(): void {
|
||||||
this.nameTag?.dispose();
|
this.nameTag?.dispose();
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,11 @@ import { Group } from '../gameobjects/group.object';
|
||||||
import { MeshPart } from '../gameobjects/mesh.object';
|
import { MeshPart } from '../gameobjects/mesh.object';
|
||||||
import { Humanoid } from '../gameobjects/humanoid.object';
|
import { Humanoid } from '../gameobjects/humanoid.object';
|
||||||
import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';
|
import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';
|
||||||
import { CharacterBodyPart, CharacterSpecification } from '../types/character';
|
import {
|
||||||
import { CharacterTextureType } from '..';
|
CharacterBodyPart,
|
||||||
|
CharacterSpecification,
|
||||||
|
CharacterTextureType,
|
||||||
|
} from '../types/character';
|
||||||
|
|
||||||
const CHARACTER_MAX_VERSION = 1;
|
const CHARACTER_MAX_VERSION = 1;
|
||||||
const CHARACTER_MIN_VERSION = 1;
|
const CHARACTER_MIN_VERSION = 1;
|
||||||
|
|
Loading…
Reference in New Issue