Computer Science Canada I need help with collision detection! |
Author: | brycemk [ Fri Nov 30, 2012 7:22 pm ] | ||
Post subject: | I need help with collision detection! | ||
Help... any ideas? <Replace all the <> with your answers/code and remove the <>> Need help with collision detection <Answer Here> I cant seem to get make the collision detection with the falling wall <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Newest version <Answer Here> |
Author: | Panphobia [ Fri Nov 30, 2012 7:31 pm ] |
Post subject: | RE:I need help with collision detection! |
(x1+x2)^2-(y1+y2)==0, for the edges etc, it checks if the two points you want to collide are occupying the same space |
Author: | Dreadnought [ Fri Nov 30, 2012 8:08 pm ] |
Post subject: | Re: I need help with collision detection! |
Panphobia wrote: (x1+x2)^2-(y1+y2)==0, for the edges etc, it checks if the two points you want to collide are occupying the same space You might want to double check your formula. @brycemk Please fill in the form, it's there for a reason. What are you trying to do? What exactly is giving you trouble? How have you tried approaching the problem thus far? |
Author: | Zren [ Fri Nov 30, 2012 8:26 pm ] |
Post subject: | Re: RE:I need help with collision detection! |
Panphobia @ Fri Nov 30, 2012 8:31 pm wrote: (x1+x2)^2-(y1+y2)==0, for the edges etc, it checks if the two points you want to collide are occupying the same space
Um. I'm thinking that you're mixing that formula up. I noticed you wrote it wrong in the other thread as well. How To Get The Distance Between Two Points (2D)
Or How Math.Distance() Works. Pythagoras Theorem (which is what circle collision detection is based off) is: a^2 + b^2 = c^2 Which is where we apply it onto the cartesian plane like so: x^2 + y^2 = d^2 [Where d is the distance from origin to point at (x, y). In other words, the hypotenuse.] Which can be rewritten to be: d = sqrt(x^2 + y^2) [Note that we only take the positive output of sqrt() as a negative distance doesn't make sense.] Which can be written as f(x, y) = sqrt(x^2 + y^2) We can use this to get the distance from point A -> point B by first centering all vectors/coordinates to be relative to point A as if it were the origin. Take: point_a = (x1, y1) point_b = (x2, y2) Which we then translate so that point_a is at origin. point_a = (x1 - x1, y1 - y1) point_b = (x2 - x1, y2 - y1) Which ends up as: point_a = (0, 0) [Origin] point_b = (x2 - x1, y2 - y1) Which we then use in our function: f(x2 - x1, y2 - y1) = sqrt((x2 - x1)^2 + (y2 - y1)^2) ~ Edit: So like, making it look pretty took way longer than I thought... |
Author: | Panphobia [ Fri Nov 30, 2012 8:32 pm ] |
Post subject: | RE:I need help with collision detection! |
yea ^ |
Author: | Panphobia [ Fri Nov 30, 2012 8:34 pm ] |
Post subject: | RE:I need help with collision detection! |
sorry forgot square root haha ![]() |
Author: | Zren [ Fri Nov 30, 2012 8:38 pm ] |
Post subject: | Re: RE:I need help with collision detection! |
Panphobia @ Fri Nov 30, 2012 9:34 pm wrote: sorry forgot square root haha
![]() You were also adding instead of subtracting. |
Author: | Panphobia [ Fri Nov 30, 2012 8:43 pm ] |
Post subject: | RE:I need help with collision detection! |
aha i mixed it all up haha, ![]() |
Author: | Panphobia [ Fri Nov 30, 2012 9:54 pm ] |
Post subject: | RE:I need help with collision detection! |
technically speaking, the square root of 0 is still 0, so you do not need to calculate it ![]() |