particle system as interactive object

This commit is contained in:
2025-11-05 17:31:21 +02:00
parent 4b722750c3
commit fd3f9a6d69
11 changed files with 165 additions and 84 deletions
+7 -9
View File
@@ -16,9 +16,8 @@ export class CharacterControls {
walkVelocity = 7
lerp = (x, y, a) => x * (1 - a) + y * a;
constructor(model, mixer, animationsMap, engine, currentAction, po, pointerControls) {
constructor(model, animationsMap, engine, currentAction, po, pointerControls) {
this.model = model
this.mixer = mixer
this.animationsMap = animationsMap
this.currentAction = currentAction
this.animationsMap[currentAction].play()
@@ -91,14 +90,13 @@ export class CharacterControls {
const current = this.animationsMap[this.currentAction]
current.fadeOut(this.fadeDuration)
toPlay.timeScale = 0.5;
//toPlay.timeScale = 1;
toPlay.reset().fadeIn(this.fadeDuration).play();
this.currentAction = play
this.actionStart = 0;
}
this.mixer.update(delta)
this.actionStart += delta;
this.cameraDelta += delta * ( pointerControls.cameraLeft * -1 + pointerControls.cameraRight * 1)
@@ -150,11 +148,6 @@ export class CharacterControls {
cameraPosition.lerp(cameraDesiredPosition, delta*2)
this.camera.position.copy(cameraPosition)
// this.camera.lookAt(new THREE.Vector3(
// this.model.position.x,
// 2,
// this.model.position.z
// ))
this.orbitControl.target.set(this.model.position.x, 2, this.model.position.z)
this.camera.lookAt(this.orbitControl.target)
}
@@ -165,4 +158,9 @@ export class CharacterControls {
pointerControls.moveForward * 1 + pointerControls.moveBackward * -1
]
}
idleReset(){
this.actionStart = 0;
this.currentAction = 'idle'
}
}
+1
View File
@@ -482,6 +482,7 @@ class GameEngine extends THREE.EventDispatcher{
let mouse = this.getMouseVector(mouseEvent, domElement);
this.raycaster.setFromCamera(mouse, this.camera);
this.clickable.update(mouse, this.camera, mouseEvent);
this.hero?.characterControls?.idleReset();
}
autoScale(object, mk = 1) {
+1 -1
View File
@@ -31,7 +31,7 @@ class Hero{
po.collider.setTranslationWrtParent({ x: 0, y: 2.0, z: 0 });
//po.collider.setActiveEvents(RAPIER.ActiveEvents.COLLISION_EVENTS);
this.characterControls = new CharacterControls(this.model, this.mixer,
this.characterControls = new CharacterControls(this.model,
this.animationsMap, gameEngine, 'idle', po, this.pointerControls)
this.clock = new THREE.Clock()