Computer Science Canada Circular Collision |
Author: | Random [ Sun Nov 07, 2004 1:03 am ] | ||
Post subject: | Circular Collision | ||
Well, here is my pitiful attempt to recreate balls bouncing off eachother. I read the tutorials on circular collision and I trying using concepts I thought I learned from thoughfuls tutorial. Im not as smart as i though. Anyways, sometimes the balls will bounce off right, but more often than not they will go into eachother and do some wierd shaking and come out and a wierd angle. I understand trig allright and I kinda understand how it is used here, but I cant get this thing working. Also, i havnt applied any kinematic equasions or whatever ill end up using to determind finishing velocity because im just trying to get the angles right. If you want me to explain any of my code ask but i hope the comments help. Anyway, any help you can give would be great. Thanks in advance.
|
Author: | wtd [ Sun Nov 07, 2004 6:40 am ] |
Post subject: | |
Well, this is pretty simple. You just have two circular objects bouncing off each other. The cool thing about circles? Every point on the edge is equally distant from it's center. This means that if you have two circles touching, the distance between their centers is the sum of their radii. So you have circle1 with a radius of 4 and circle2 with a radius of 1. If the distance between their centers is greater than 5, they are not in contact. If the distance is exactly 5 (or as close as you can get in pixels), then they're in contact. The only trigonometry you need to know is having the ability to find the hypotenuse of a triangle. |
Author: | Random [ Sun Nov 07, 2004 10:36 am ] |
Post subject: | Collision |
Yea, i can get the collision detection, so it knows when the balls collide, but it is my angles that are messed up. You'd use sine theta because for x because that is equal to adjacent / hypoteneuse, and the adjacent is horizontal. Then I'd use cosine theta because that is opposite / hypoteneuse, and the opposite is vertical. That make sence? The problem is, when the new x and y velocities are calculated sometimes they are in the wrong dirrection so one ball will go through the other. I think this is because a velocity continues to be positive when it should be negative or vice-versa. Understand what I'm saying? I was just wondering how it could be done so that the velocity is always in the proper dirrection instead of it sometimes being right and sometimes not. Thanks for your reply. I think I'll try messing around with my trig some more. Im hoping the problem is some small thing i missed (atleast i hope so). I appreciate your time. +10 bits |
Author: | Delos [ Sun Nov 07, 2004 10:51 am ] |
Post subject: | |
I'm not sure if you've read these or not, but here's a link to a number of tutorials on the topic. |
Author: | Cervantes [ Sun Nov 07, 2004 10:58 am ] |
Post subject: | |
Random wrote: You'd use sine theta because for x because that is equal to adjacent / hypoteneuse, and the adjacent is horizontal. Then I'd use cosine theta because that is opposite / hypoteneuse, and the opposite is vertical. That make sence?
isn't it the other way around? SOHCAHTOA |
Author: | Random [ Sun Nov 07, 2004 11:12 am ] |
Post subject: | |
Quote: isn't it the other way around?
SOHCAHTOA Wow... dont i feel like an idiot. I guess you found my stupid mistake before me. Thank you so much! And thanks for the link to the tutorials delos. I did read them, but thanks. |