eep! breakout clone, may ball always get stuck!

Started by
10 comments, last by mickey 21 years, 7 months ago
on the paddle, on the sides of the level and on the blocks as well! do i have to set the position after a collision? why can''t i just reverse the velocity? ie, ballpos += ballvel * elpasedtime; if ball collides with anything ballvel = -ballvel; many thanks
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Advertisement

I don''t know why it gets stuck, it might be worth updating the position so it''ll definitely be outside the thing it struck next frame, but, you shouldn''t have

ballVel = -ballVel;

That would make it bounce straight back off every surface it hit. So

if (hitHorizontalSurface)
{
ballVel.y *= -1;
}
if (hitVerticalSurface)
{
ballVel.x *= -1;
}

might be worth a try. If you have angled surfaces you''ll want a better approach.
oh yes, i do that, depends on the angle and which part the ball hits the block, i just made that to simplify the things.

okey i''m thinking about that too, updating the position, but someone advices that if my col det is good, i don''t need to update it anymore. My ball gets stuck sometimes on my ''indestructible block''. Also, updating the position? how.., i don''t know the exact coordinate/part the ball hits the block. i just know which ''area'' it hits

thanks!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
okey, i've also discovered something, if my ball moves slow, collision is perfect, but if my ball moves fast, well, there goes the stuck

hmm, okey here's a sample screenshot from the game,

www.info.com.ph/~davidang/screenshot.jpg




[edited by - mickey on September 8, 2002 11:31:18 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
think about it. your ball moves into the object. collision get detected => velocity reversed. next frame is a little shorter => ball does not move 100% out of the object again => collision detection => velocity reversed. from this moment on, he''s stuck..

don''t reverse, set directly.. set it to a positive value, if you want to let him reflect into the positive direction, or a negative one else. 4 possiblities instead of 2, like now (leftright/topbottom)

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

yes that's what i've thought of, the game runs very fast so the ball hasn't had the time to get off.., ehm., what do you mean by your next statement?

quote:don't reverse, set directly.. set it to a positive value, if you want to let him reflect into the positive direction, or a negative one else. 4 possiblities instead of 2, like now (leftright/topbottom)


particulary, 'set directly' ?




[edited by - mickey on September 8, 2002 11:33:32 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
To do ''proper'' collision detection you need to find the collision before it happens - and if it WILL hit the wall in the next frame you reverse the velocity and calculate the new position, this should stop the possibility of it forever bouncing.
calculate? so you mean, after i detected a collision, i should set a new position for the ball huh? but how will i go by knowing the 'exact' coordinate on which part of the 3d block my ball hits? so this way, i could like, get the exact coordinate and subtract/add 0.1 to account for the ball being stuck,

EDIT: ehm, help. thought it was going to be easy., but how do I predict if the ball's about to hit the block?

this is how i check as of now,

compare ball pos +/- bounding sphere with blockpos +/- bounding box;
if intersect, then hit = true;
if hit then, bounce appropirately

you can see how i move my ball above,

thanks,

[edited by - mickey on September 8, 2002 12:03:03 PM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
hiya,

okey discovered another thing,

if i use a constant value to replace the elapsed time, ie,

pos += vel * 0.005;
instead of
pos += vel * elapsedtime;

then i wouldn''t have any problem anymore, but as you know that is bad because if my game runs at higher fps then the movement of the game would be faster and vice versa,

so what seems to be the problem using the elpased time?

i''d also like the solutions for my questinos above

many thanks,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
what i mean with set directly.. assuming +x is to the right, and +y to the bottom:

instead of
if(hit_top || hit_bottom) y *= -1;
if(hit_left || hit_right) x *= -1;
like you do currently, do it like that:
if(hit_top) y = -abs(y);
if(hit_bottom) y = abs(y);
if(hit_left) x = abs(x);
if(hit_right) x = -abs(x);

think about it.. if you hit the top, you don''t invert your y coordinate, you set it into a direction going away from the topside => upwards.. thats what i mean with set direcly..

what you talk about, btw, is fixed timestep.. check google for fixed timestep..

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement