Feature: guests have collisions + different sizes

This commit is contained in:
Dejvino 2025-12-30 18:20:03 +00:00
parent b76810e883
commit c17311036b

View File

@ -9,7 +9,7 @@ const stageDepth = 5;
const length = 25;
const numGuests = 150;
const moveSpeed = 0.8;
const movementArea = { x: 20, z: length, y: 0, centerZ: -2 };
const movementArea = { x: 15, z: length, y: 0, centerZ: -2 };
const jumpChance = 0.01;
const jumpDuration = 0.3;
const jumpHeight = 0.2;
@ -54,6 +54,9 @@ export class PartyGuests extends SceneFeature {
const group = new THREE.Group();
const scale = 0.85 + Math.random() * 0.3;
group.scale.setScalar(scale);
// Body
const body = new THREE.Mesh(bodyGeo, material);
body.position.y = 0.7; // Center of capsule (0.8 length + 0.3*2 radius = 1.4 total height. Center at 0.7)
@ -92,7 +95,7 @@ export class PartyGuests extends SceneFeature {
// Position
const pos = new THREE.Vector3(
(Math.random() - 0.5) * 10,
(Math.random() - 0.5) * movementArea.x,
0,
movementArea.centerZ + ( rushIn
? (((Math.random()-0.5) * length * 0.6) - length * 0.3)
@ -129,10 +132,35 @@ export class PartyGuests extends SceneFeature {
if (this.guests.length === 0 || !state.partyStarted) return;
const time = state.clock.getElapsedTime();
const minDistance = 0.8; // Minimum distance to maintain
this.guests.forEach(guestObj => {
this.guests.forEach((guestObj, i) => {
const { mesh, leftArm, rightArm } = guestObj;
// --- Collision Avoidance ---
let separationX = 0;
let separationZ = 0;
for (let j = 0; j < this.guests.length; j++) {
if (i === j) continue;
const otherMesh = this.guests[j].mesh;
const dx = mesh.position.x - otherMesh.position.x;
const dz = mesh.position.z - otherMesh.position.z;
const distSq = dx*dx + dz*dz;
if (distSq < minDistance * minDistance && distSq > 0.0001) {
const dist = Math.sqrt(distSq);
const force = (minDistance - dist) / minDistance;
separationX += (dx / dist) * force;
separationZ += (dz / dist) * force;
}
}
const separationStrength = 2.0;
mesh.position.x += separationX * separationStrength * deltaTime;
mesh.position.z += separationZ * separationStrength * deltaTime;
if (guestObj.state === 'WAITING') {
// Face the stage (approx z = -20)
const dx = 0 - mesh.position.x;