I’m trying to check if a img is hitting a cloned img but when testing it seems to be thinking its hitting the clone when it is not
const moveInterval = setInterval(() => {
const rect = clonedBullet.getBoundingClientRect();
if (rect.right >= window.innerWidth) {
clearInterval(moveInterval); // Stop moving
document.body.removeChild(clonedBullet); // Delete the clone
} else {
clonedBullet.style.left = (rect.left + 2) + "px"; // Move right & detect hit
if (Player.y < clonedBullet.y + clonedBullet.height / 2 && Player.y > clonedBullet.y - clonedBullet.height / 2) {
if (Player.x < clonedBullet.x + clonedBullet.width / 2 && Player.x > clonedBullet.x - clonedBullet.width / 2) {
Hp = Hp - 1
document.getElementById("hpHeader").textContent = Hp;
}
}
}
}, 5);
I’ve tried to change the box where it’s checking I also tried to do meany things but I have not worked on this for a pretty long time so I can’t remember.