When Two Objects Collide

BlitzMax Forums/BlitzMax Beginners Area/When Two Objects Collide

Matt McFarland(Posted 2005) [#1]
If I were to make two instances of the same type (circles), and have them bouncing off the corners of the screen they simply overlap each other if they cross paths.

Now if you were to create code for them to collide into each other. How do you define where they go after the collision? How do you define that they have reached a collision?

Since Ball:TBall is the same as another Ball:TBall - How do you compare two Ball:TBalls?


ImaginaryHuman(Posted 2005) [#2]
I think you would need to keep track of the angles at which they are travelling, so that when they collide, you figure out the `rebound angle` and combine it with the original angles, to move off in the right direction. I think that would involve taking the angle from the center of each circle to the point where the circles collided (which you work out with pythagoras?). Something like that.


Matt McFarland(Posted 2005) [#3]
But how would I find out what the angle is in the first place? The ball is moving by an x and y velocity vector.

If the ball hits a part of the screen either the x or the y vector flips.

How does the program know what the angle of the ball is when it makes a collision. How does the program know when two balls have collided into each other? they are two circles goverened under the same Type code, so their scripts run at the same time. How do they know they have collided when they are the same?


Dubious Drewski(Posted 2005) [#4]
"Type circleType"
A Type declaration is a blueprint for your circles, that's all.
When you write this:

circle[1] = new circleType

a circle object was created using circleType as a blueprint.
So, to process the movement for this, you might do this:

for local a = 0 to 20
circle[a].move
circle[a].draw
next

Therefore, code cannot run at the same time as other
code. Code always runs sequentially.


Dubious Drewski(Posted 2005) [#5]
I don't know that answer to your question, but here is me
trying to figure it out. It might work:




Loonie(Posted 2005) [#6]
use your velocity vector to figure it out...you know the definition of a vector, right?

to figure out if they collided (circles) the distance between them < 2r


Dubious Drewski(Posted 2005) [#7]
You'd also have to compute all of the kinetic energy entering
the system then divy it out to each circle according to it's
mass. That's how you decide how fast each new vector
should be. The direction of the vector would be figured out
from a chart like above.

I think...


Dreamora(Posted 2005) [#8]
If both "balls" have the same weight, their speed won't change (if you don't use elasticity factors that would slow both balls by the same factor), as their impuls would divided into the same "parts" before and after the impact