I am working on a school assignment and I am stuck on one part. I need to change a if statement
1 2 3 4 5 6 7 8 9
bool SphereCollision(Vector3 p1, float r1, Vector3* v1, float m1,
Vector3 p2, float r2, Vector3* v2, float m2,
float E) {
Vector3 temp;
temp = Subtract(p2, p1); //Here, p1 and p2 are the center of each sphere
//Add the proper sphere-sphere collision detection here in this one line of the if statement:
if (temp.length() <= sqrt( r1+r2) ) {
I added the sqrt(r1+r2). It was if(temp.length()<=r1). I know the formula for collision detection is if the distance is less then the radii then there is a collision. I have tried to change the temp.length() to sqrt(temp.length()) according to the book that I have and it stops before it even touches it. I just need some help figuring out how to code the correct line for it to work.
From what the lab says it just shows the length. I believe that is the distance between the spheres. With that looking at my book it I just noticed something that I might have missed before. I saw where they had a code very simular to thisif (temp.length() <= r1+r2 ) . So I think the problem I am having is in these lines.
1 2 3 4 5
//modify these two lines of code so that the correct final speed formulas are used:
//hint: look at the last set of formulas from the Week 6 lecture.
v2f = v2i;
v1f = v2f;
No I'm not breaking the rules by asking for help. I'll work on them and see if that is the problem.