I am making a voxel game. (think minecraft) Currently I’m calling it It’s Like Minecraft But It’s Not (Minecraft), or ILMBIN for short.
For the block selection, I am calling the block textures bID + a number (bID0 for example) I have a system where a q press decriments a variable called currentselect. an e press increments the same variable. This is used in the following variable called currentblock. This variable goes like this:
var currentselect = 0;
var currentblock = "bID" + currentselect;
In my head this adds up to bID0, which is a block texture. then when you place a block it’s texture should be bID0, but instead it makes the scene freeze.
You have a function that does not exist ‘updatePosition’.
That’s probably what’s causing your problem.
function lockChangeAlert() {
if (document.pointerLockElement === canvas ||
document.mozPointerLockElement === canvas) {
console.log('The pointer lock status is now locked');
document.addEventListener("mousemove", updatePosition, false);
} else {
console.log('The pointer lock status is now unlocked');
document.removeEventListener("mousemove", updatePosition, false);
}
}
block.material = currentblock; is affecting the string to the material. I you want to do this you need to store your materials in a dictinary and access by name or you could use an array and simply access by index.