could you help me out with some code for some reason its not working but there isn’t any errors showing up?
// Create a new application
const app = new pc.Application(document.getElementById('application'), {
mouse: new pc.Mouse(document.body),
touch: new pc.TouchDevice(document.body),
keyboard: new pc.Keyboard(window)
});
// Set the canvas to fill the window
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
// Create a basic scene
app.start();
// Create a camera
const camera = new pc.Entity();
camera.addComponent('camera', {
fov: 45,
nearClip: 0.1,
farClip: 1000
});
camera.setPosition(0, 5, 10);
app.root.addChild(camera);
// Create a light
const light = new pc.Entity();
light.addComponent('light', {
type: 'directional',
color: new pc.Color(1, 1, 1),
intensity: 1
});
light.setEulerAngles(45, 0, 0);
app.root.addChild(light);
// Create a simple block
function createBlock(x, y, z) {
const block = new pc.Entity();
block.addComponent('model', {
type: 'box'
});
block.setPosition(x, y, z);
app.root.addChild(block);
}
// Create a grid of blocks
for (let x = -5; x <= 5; x++) {
for (let z = -5; z <= 5; z++) {
createBlock(x, 0, z);
}
}
// Handle keyboard input for movement
const speed = 0.1;
app.keyboard.on(pc.EVENT_KEYDOWN, function (event) {
const cameraPos = camera.getPosition();
if (event.key === pc.KEY_W) {
camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z - speed);
}
if (event.key === pc.KEY_S) {
camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z + speed);
}
if (event.key === pc.KEY_A) {
camera.setPosition(cameraPos.x - speed, cameraPos.y, cameraPos.z);
}
if (event.key === pc.KEY_D) {
camera.setPosition(cameraPos.x + speed, cameraPos.y, cameraPos.z);
}
});
// Update the application
app.on('update', function (dt) {
// Update logic here
});
// Function to initialize the scene when added to an entity
function initializeScene(entity) {
entity.addChild(camera);
entity.addChild(light);
for (let x = -5; x <= 5; x++) {
for (let z = -5; z <= 5; z++) {
createBlock(x, 0, z);
}
}
}
// Example of adding the scene to an entity
const mainEntity = new pc.Entity();
app.root.addChild(mainEntity);
initializeScene(mainEntity);
this is the code that isn’t working