10-20-2022, 03:48 AM
Looks more like Gary from Sponge Bob.
Pete
Pete
|
Angle Collisions
|
|
10-20-2022, 03:48 AM
Looks more like Gary from Sponge Bob.
Pete
10-20-2022, 01:51 PM
10-20-2022, 02:52 PM
OK a ball with a heading of ba (Radians or Degrees) moves like this: (ba = ball Angle)
newX = oldX + speed * Cos(ba in Radians = _D2R(ba in degrees)) newY = oldY + speed * Sin(ba in Radians = _D2R(ba in degrees)) or dx = change in x = Cos(ba in Radians = _D2R(ba in degrees)) dy = change in y = Sin(ba in Radians = _D2R(ba in degrees)) and newX = oldX + dx newY = oldY + dy When ball is a radius away from a rectangular wall it gets reflected off wall such that: if wall is left side dx = -dx if wall is right side dx = -dx if wall is top dy = - dy if wall is bottom dy = -dy That's easy to code and why Ping Pong so easy to code. But you need to update ball heading too, ba = _Atan2(dy,dx), if you use ba for collisions with say other balls. A little more tricky with _Atan2 that returns an angle in Radians and between -Pi and Pi usually.
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
10-20-2022, 04:21 PM
Thanks for this info...I was hoping this next part wouldn't be as difficult as the reflection.
I'm going to keep this really simple for now. I'll start with a single angled wall (set by mouse) and then let a ball drop onto it. And see if I can get the collision point worked out at any angle.
Here is my circle intersect line segment detector, thanks to james2464 Random Line Segment Container Problem which I had to create to detect when a ball enters a line segment:
Code: (Select All) ' return count of how many points overlap segment
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
10-21-2022, 07:10 PM
I have a line detector worked out using the same vector info from the reflection. There are two detections involved. One is to detect how far the ball is from the side of the line, and the other checks the distance from the end of the line. You can see these lines by holding the mouse button, or just check the collision without any lines.
The side checking method uses the vector dot product, which was a calculation already used to get the reflection angle. If this distance (line N in program notes) is less than the ball radius, there is a collision with the line. Code: (Select All) 'vector reflection and line detection demo
10-21-2022, 07:20 PM
Looks like a good start of a billiards game. I would assume round on round surface collisions with the balls instead of just a ball into a cushion, would require even more calculations.
Pete
Yeah! can't wait to see it applied to your random container.
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
10-22-2022, 12:09 AM
Looks like everything needed is there, incoming vector, relfection vector, line detection and edge detection. Nice job.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
10-22-2022, 10:29 PM
Yeah I think the math is there now, but programming is a different story. So far I've failed to get this to work. The bounces sometimes go in the wrong direction, the ball goes through the line sometimes. The problem seems to be that the calculations are sometimes using wrong info, backwards +/- values etc so I'll need to sort all that out. One thing I'll be thrilled to get right is breaking up a frame. Sometimes the ball is moving at say 10 pixels per frame and it could go past the line by 7 pixels for example. I'd like to somehow correctly break that into two parts so that the ball bounces back those 7 pixels in the new direction. If that makes sense.
|
|
« Next Oldest | Next Newest »
|
| Possibly Related Threads… | |||||
| Thread | Author | Replies | Views | Last Post | |
| Angle difference | bplus | 8 | 1,623 |
01-31-2023, 10:32 PM Last Post: OldMoses |
|