Archived

This topic is now archived and is closed to further replies.

eep! breakout clone, may ball always get stuck!

This topic is 5573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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,

[url]www.info.com.ph/~davidang/screenshot.jpg [/url]




[edited by - mickey on September 8, 2002 11:31:18 AM]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Im guessing that if elapsed time is large, then your ball goes past the collision wall ( which would happen if you were just doing something like if xpos=xbound instead of if xpos>=xBound ).

Well.. actually it should be xPos+(elapsedTime*xVel)>=xBound then reverse velocity and calc new position.

Share this post


Link to post
Share on other sites
stevenmarky, thanks! my problems has just vanished! i don''t calculate the new position becuase i don''t know how to get the exact coordinate where the ball hits the block so i just reverse it,

devepermen, i don''t see any difference between using the abs and just appending a negative sign before the velocity. and you said

quote:

if you hit the top, you don''t invert your y coordinate


but in your code you made this?
if(hit_top) y = -abs(y); ??

isn''t that inverting as well? i''m sorry but i don''t get it, hope you culd explain more, thanks

Share this post


Link to post
Share on other sites