For my project I decided upon doing a top-down shooting game where the player would fight zombies (sprites are a work in progress). The main concept is that the player would be able to use a variety of weapons to attack an endless wave of zombies. This week, I worked on the array to have zombies endlessly spawn and the player’s movement.
The biggest challenge was getting the enemies to follow the player not with lerp, but to slowly puruse the player. This was the code that I had to use to get the ‘enemies’ to follow the player in a linear steps-per-frame model.
for (let ball of balls) {
//direction ball is "facing"
let direction = createVector(playerX - ball.x, playerY - ball.y);
//playerSpeed control
direction.setMag(ballSpeed);
ball.add(direction);
for (let ball of balls) {
//direction ball is "facing"
let direction = createVector(playerX - ball.x, playerY - ball.y);
//playerSpeed control
direction.setMag(ballSpeed);
ball.add(direction);
for (let ball of balls) { //direction ball is "facing" let direction = createVector(playerX - ball.x, playerY - ball.y); //playerSpeed control direction.setMag(ballSpeed); ball.add(direction);