Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Getting Angles  (Read 3260 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Getting Angles
« on: September 15, 2008, 09:04:23 pm »
Hi doing a pong clone i need to know how to get collission-angles when a ball hits a round target, is there any function?

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Getting Angles
« Reply #1 on: September 15, 2008, 09:33:00 pm »
here is an article on gamasutra that describes how to collide pool balls corectly .. it might be a bit advanced .. and have abit much math in it .. but it might help you :)

http://www.gamasutra.com/features/20020118/vandenhuevel_01.htm

But if you are doing a pong clone you could go the ultra cheap way and just set the ricocheting angel depending on the offset from the paddles middle point :)

the best lesson one can learn when making games is to cheat as much as possible :)
//Zzzarka

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Getting Angles
« Reply #2 on: September 15, 2008, 09:48:35 pm »
the vectormathematics seems to be not my problem, but i have problems with getting collission-point,  especially because there are real circles but round corners   :

                            O

                             (========)
in fact i think my only problem is how to manage the collission

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Getting Angles
« Reply #3 on: September 15, 2008, 10:15:10 pm »
There's no "function" for what you want to do.  What you're working with is collision detection and handling which is an advanced topic.  But you just said you didn't want "expert" posts.  You need to make up your mind.
If you're expecting someone to post a few lines of code to solve your problem, it's just not going to happen.
You have a few choices here:

1) Just use a bounding box and deflect based on offset from the center of the paddle or something (as previously suggested).  It won't look awesome, but it's simple and good for learning.  You could also just draw the paddle as a sharp box without rounded corners and then it would look correct too.

2)  Mess around with "pixel perfect" stuff and try and fake it.  I see no point in going down this road since doing an iterative pixel alpha compare will only give you a yes/no on collision with no other useful information, such as a penetration vector (which is what you need in this case).  By the time you got that working, you'll be very close to implementing correct collision detection anyway.
This is just an inherent problem with this type of collision detection.  You get nothing but a yes/no out of it.

3)  Do it "right."  This is not necessarily the best option if you are just trying to make a game and want to avoid advanced topics.  If that's the case, go for option #1.
The correct way involves breaking your collision volume up into shape primitives.  (For a rounded paddle, probably a box and 2 circles on the ends.)  Then you do separate collision testing functions for each possible primitive interaction (probably just sphere-to-box and sphere-to-sphere in your case.)
In those functions, you'll be able to calculate exact overlaps and get other useful information.  (For example the shortest path back out of a collided state which could be used for figuring out a "bounce angle.")
Also, if you were treating the ends of the paddles as circles and not pixel arrays, the information in that gamasutra article would probably be far more relevant.  (Although I haven't actually read it.)

Let me know what you want to do and I can try to help you.