Basic Shooter Game Problem... Please Help!
I have a bug in my game code, but cannot seem to find the fix to it. Recently I developed a simple shooter mechanism into a fun, little game in which a ninja faces off against zombies (practicing javascript). However, I noticed that while it worked fine from a distance, the moment the zombie was closer than ~100-200 pixels, there is an error, which states "Uncaught TypeError: Cannot read property 'x' of undefined (main: line 46)." My code is written in a javascript framework called p5js. The code is here: https://editor.p5js.org/MattGrim/sketches/BkP-MJe-V To see the error in action, wait until the zombie is close to approaching the character and then move in front of it (w or s) and fire (spacebar). What are the possible syntax/code writing mistakes that would cause this specific error, and what should I look out for? Please help me find the bug. P.S. Next to the main.js title over the code box, there is a > arrow to the left of it. Clicking on that should give you access to all of the files.