2 ms·
I wrote a simple pong game once for a CS class, and in my case a vibrating ball was caused by simply negating velocity on a collision rather than setting its si
by nitrogen 16y ago
I wrote a simple pong game once for a CS class, and in my case a vibrating ball was caused by simply negating velocity on a collision rather than setting its sign. It's better to do something like this (using C pseudocode as that's my native language):
if(collision) {
switch(side_of_screen) {
case LEFT:
horiz_speed = abs(horiz_speed);
break;
case RIGHT:
horiz_speed = -abs(horiz_speed);
break;
case TOP: // Positive Y is downward
vert_speed = abs(vert_speed);
break;
case BOTTOM:
vert_speed = -abs(vert_speed);
break;
}
}