Game Development Community

Breakout Issues

by Justin Proffitt · in Technical Issues · 04/24/2009 (7:33 pm) · 4 replies

I am following the breakout tutorial and I appear to have a couple issues which I just cant fix.

1) When the paddle is moving fast enough to add impulse force to the ball, it seems that the ball goes straight through the paddle at a higher velocity (sometimes at an angle). I copied and pasted the code directly from the tutorial and double checked it, so it appears to be a mathematical problem.

Script:

function ballClass::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points) {
if (%dstObject.class $= "paddleClass") {
%dstObject.schedule(500,"makeHittable");
%dstObject.setCollisionActive(0,0);
%speed = getword($thebase.getlinearVelocitypolar(),1);
if (%speed > 150) {
%force = t2dVectorScale(%normal,(-%speed*2));
%srcObject.setImpulseForce(%force, false);
}
%r=getRandom(1,2);
%hitsound="shieldhit"@%r;
alxPlay(%hitsound);
$wallbang.setPosition(%points);
$wallbang.playEffect(false);
}else if (%dstObject.class$="wallClass") {
alxPlay(wallhit);
$wallbang.setPosition(%points);
$wallbang.playEffect(false);
}else if (%dstObject == $thetileset) {
$wallbang.setPosition(%points);
$wallbang.playEffect(false);
$thetileset.clearTile(%dstRef);
}


}
(No syntax issues, dont worry about that)

2. After applying the hack in the 3rd part of the tutorial, I noticed that when the ball hits the paddle, the base appears to 'hop' for 500 milliseconds; while the collision of the base is disabled it appears to default to a lower position on the y-axis (visually higher).

Im most concerned with the first issue, I am sure I will figure out whats wrong with the base briefly after posting this. Any help would be appreciated! Here's a link to the breakout tutorial:

http://tdn.garagegames.com/wiki/TGB/BreakoutTutorial

About the author

I am a college student majoring in physics. As it so happens I like programming, a hobby which extends my profession in web design.


#1
04/25/2009 (7:31 am)
Try changing
%force = t2dVectorScale(%normal,(-%speed*2));
to
%force = t2dVectorScale(%normal,(%speed*2));
#2
05/10/2009 (9:51 pm)
Actually I did that, it appears to have fixed the issue for the most part. However now I notice that the ball will randomly pass through the paddle sometimes when exceeding speeds of 150, and in rare cases bounce through the paddle.
#3
08/04/2009 (2:39 pm)
Don't know if you've found an answer to this yet, but here's what I found.

The effect you're seeing is caused when the collision of the bumper gets turned off for a little while, then the base leaps back to it's correct position, once the collision gets turned back on the base gets pushed down again.

Essentially the collision polygon of the bumper is interfering with the collision polygon of the base, pushing the base down. I'm too inexperienced to understand had to correct this the "right" way so I simply changed the collision polygons of both the base and the bumper so that they didn't overlap. Problem solved - although I'm still having you first problem.

#4
08/13/2009 (8:06 pm)
I left that project, however I have an idea for trouble shooting it... Add the following line right under the "If(%speed > 150){" line:
echo(%normal);

Then after "%force = t2dVectorScale(%normal,(-%speed*2));" put:
echo(%force);

Then test it out until you run into that problem, I am not sure what you should look for, but chances are its a consistent mathematical issue.