2d ball bouncing
Blitz3D Forums/Blitz3D Beginners Area/2d ball bouncing
| ||
How can i bounce balls in 2d, if someone could put this inside a function or something, and give me an explanation for how this works, I'd appreciate it. (been searching the forums, can't find anything that quite cuts it) |
| ||
Have you tried looking throught the sample games? I'd try the code from "Kong" in Game Programming for teens. I think this is a collision thing. I'd be more detailed but I don't have time, sorry. |
| ||
err...what??? |
| ||
BallX=BallX+BallMoveX If BallX > 100 Then BallMoveX=BallMoveX*-1 Off the top of my head, BallMoveX is how much the ball moves. Just opposite it when it hits a boundary. Do the same thing for the Y vaules and you have a bounce effect. |
| ||
I've already done something like that, except that only works for 4-directional bouncing, it won't bounce of diagnal surfaces. |
| ||
|
| ||
Oops,... just saw your last post,... didn't know you were looking for angles. I don't have time to make that work tonight. Edit,... did a bit more on it anyways How are you drawing your angles? You will need to find the angle of the line, and how it intersects the velocity line of the ball. Then you change the velocity to the new value. Same concept as above, but instead of detecting the screen edge you are detecting the angled lines. Edit: ok, I grabbed some code from the archives for the line collision. It is missing some of the collisions because the collision response is only changing the Y velocity. You will need to determine the proper angle to give the correct x and y velocities. |
| ||
See my revised code near the bottom. This does correct reflection in 2d. You could adapt it to work with Pongo's code above. http://www.blitzbasic.com/Community/posts.php?topic=65410#730520 |