I'm working on a basic first person camera controller in p5.JS, and I'm using the move function inside of an if statement (uses keyIsDown) and it still moves the camera when the key isn't pressed (I mean like its down for a second then no longer pressed).
I've also tried using while () but that crashes it.
let d;
let cam;
let x, y, z;
let img;
let floor_texture;
//place holder image
floor_texture = 'https://miro.medium.com/max/1400/1*WI5Zw1eKEKNmRX3zreeUHw.png';
function preload() {
img = loadImage(floor_texture);
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
x = 0;
y = 0;
z = 0;
cam = createCamera();
}
function draw() {
d = dist
background(255);
cam.pan(-movedX * 0.005);
cam.tilt(movedY * 0.005);
fill('white');
sphere(25);
fill('red');
texture(img);
translate(0, 350, 0)
box(5000, 500, 5000)
if (keyIsPressed && keyCode === 69) {
requestPointerLock();
}
cam.move(x, y, z);
if (keyIsDown(87)) {
z -= 0.1;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js"></script>