For some reason, in the game that I am attempting to make for a class project whenever the player hits an asteroid at speed, the playerHealth variable goes down by multiple numbers instead of by one. The below are functions from my Asteroid class.
void collision() {
if (asteroidX <= 0) {
respawn();
}
//if (!invincible) { //unimplemented invincibility frames
for (int i = 0; i < asteroids.length; i++) {
if (dist(asteroids[i].asteroidX, asteroids[i].asteroidY, player.playerX, player.playerY) < asteroids[i].asteroidSize + player.playerSize) {
respawn();
playerHealth -= 1;
println(playerHealth);
// }
}
}
}
void respawn() {
asteroidX = width*1.3; //spawn beyond screen
asteroidY = random(height);
asteroidSize = random(10, 25);
asteroidSpeed= random(2, 5);
}
Does anyone know why exactly this is happening? I have a vague feeling but I’m too new at this to really understand what exactly is to be fixed. I’m down for posting my full code if that’s necessary.