P
predikit
Guest
I am attempting to work through the code of making the Breakout Game before I actually open the tutorial and I've begun to notice an odd behavior.
If statements are interfering with each other, and I can't for the life of me understand why. I've gotten all the rebound directions to work except one, but the condition was definitely programmed in the collision check. I got so frustrated and decided to restart from the beginning and test specifically for each condition as I worked through the logic.
As an example, take this snippet:
The first check for < 90 works, until I code the check for between 90 and 180, then the first condition check for collision will fail and the object passes right through. As soon as I comment out the 2nd If statement, the first one begins working again.
It is my understanding that a logical check for conditions are just that, and should NOT have any affect past it's local scope.
Any ideas as to what's going on here?
If statements are interfering with each other, and I can't for the life of me understand why. I've gotten all the rebound directions to work except one, but the condition was definitely programmed in the collision check. I got so frustrated and decided to restart from the beginning and test specifically for each condition as I worked through the logic.
As an example, take this snippet:
Code:
var angle = 0;
//mirrors right rebound
if (direction < 90 ) {
angle = (90 - direction);
direction = (direction + (angle * 2));
}
//mirrors left rebound
if ((direction > 90) && (direction < 180)) {
angle = (direction - 90);
direction = (direction - (angle * 2));
}
It is my understanding that a logical check for conditions are just that, and should NOT have any affect past it's local scope.
Any ideas as to what's going on here?