Refactor spawnSpiritWithOffset to adjust spawn position based on timeSinceSpawnMs
This commit is contained in:
@@ -439,23 +439,26 @@ async function spawnSpirit(spiritData) {
|
||||
}
|
||||
|
||||
async function spawnSpiritWithOffset(spiritData, timeSinceSpawnMs = 0, spiritIntervalMs = 20000) {
|
||||
let spawnPos = { x: 0, y: spinnerController && spinnerController.spinnerRed ? spinnerController.spinnerRed.position.y - 1.5 : 15, z: 0.88 };
|
||||
const modelUrl = spiritData['Model URL'] || spiritData.modelUrl; // Fallback!
|
||||
const { scene: gltfScene } = await gltfLoader.loadAsync(modelUrl);
|
||||
|
||||
// Berechne Lebenszeit-Offset
|
||||
let offset = 0;
|
||||
if (typeof timeSinceSpawnMs === 'number' && timeSinceSpawnMs > 0) {
|
||||
offset = timeSinceSpawnMs / 1000;
|
||||
}
|
||||
// Die gesamte Lebenszeit des Spirits (z.B. 20s) - das Offset
|
||||
// Standard-Spawnhöhe:
|
||||
let startY = spinnerController && spinnerController.spinnerRed ? spinnerController.spinnerRed.position.y - 1.5 : 15;
|
||||
// Offset in Sekunden:
|
||||
let offset = (typeof timeSinceSpawnMs === 'number' && timeSinceSpawnMs > 0) ? timeSinceSpawnMs / 1000 : 0;
|
||||
// Die Lebenszeit des Spirits:
|
||||
let lifeTime = (spiritIntervalMs ? spiritIntervalMs : 20000) / 1000;
|
||||
|
||||
// Bei Offset: Spirit kürzer anzeigen
|
||||
// Y-Verschiebung pro Sekunde (wie im update!):
|
||||
const despawnSpeed = 0.8; // ACHTUNG: identisch halten mit update()!
|
||||
|
||||
// Spawn-Position anpassen:
|
||||
let spawnPos = { x: 0, y: startY - (despawnSpeed * offset), z: 0.88 };
|
||||
|
||||
const modelUrl = spiritData['Model URL'] || spiritData.modelUrl;
|
||||
const { scene: gltfScene } = await gltfLoader.loadAsync(modelUrl);
|
||||
|
||||
const spirit = new Spirit(scene, gltfScene, spiritData, spawnPos);
|
||||
spirit.clock.start();
|
||||
if (offset > 0 && offset < lifeTime) {
|
||||
spirit.clock.elapsedTime = offset; // <<---
|
||||
spirit.clock.elapsedTime = offset;
|
||||
}
|
||||
spirit.lifeTime = lifeTime;
|
||||
activeSpirits.push(spirit);
|
||||
|
||||
Reference in New Issue
Block a user