#### Archived

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

# eep! breakout clone, may ball always get stuck!

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

## 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 on other sites

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 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 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 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

##### 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 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 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 on other sites
hiya,

okey discovered another thing,

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

pos += vel * 0.005;
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 on other sites
what i mean with set directly.. assuming +x is to the right, and +y to the bottom:

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

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633333
• Total Posts
3011404
• ### Who's Online (See full list)

There are no registered users currently online

×