Add function to clone runtime character shape and create runtime NPC from definition

This commit is contained in:
2026-04-13 23:56:58 +02:00
parent a5a1b4d68c
commit dc791efab1

View File

@@ -374,6 +374,46 @@ function createRuntimeCharacterShape(
}
}
function cloneRuntimeCharacterShape(
shape: FirstPersonPlayerShape
): FirstPersonPlayerShape {
switch (shape.mode) {
case "capsule":
return {
mode: "capsule",
radius: shape.radius,
height: shape.height,
eyeHeight: shape.eyeHeight
};
case "box":
return {
mode: "box",
size: cloneVec3(shape.size),
eyeHeight: shape.eyeHeight
};
case "none":
return {
mode: "none",
eyeHeight: shape.eyeHeight
};
}
}
export function createRuntimeNpcFromDefinition(
npc: RuntimeNpcDefinition
): RuntimeNpc {
return {
entityId: npc.entityId,
actorId: npc.actorId,
name: npc.name,
visible: npc.visible,
position: cloneVec3(npc.position),
yawDegrees: npc.yawDegrees,
modelAssetId: npc.modelAssetId,
collider: cloneRuntimeCharacterShape(npc.collider)
};
}
function clonePlayerStartMovementCapabilities(
capabilities: PlayerStartMovementCapabilities
): PlayerStartMovementCapabilities {
@@ -841,7 +881,7 @@ function buildRuntimeSceneCollections(
};
npcDefinitions.push(npc);
if (npc.active) {
runtimeEntities.npcs.push(npc);
runtimeEntities.npcs.push(createRuntimeNpcFromDefinition(npc));
}
break;
}