Original Post
Hey, I'm trying to make an asteroids clone an I'm wandering how to reposition circles when they collide.
It would be easy to just do velocity = -velocity but the objects move fast so when the collide they get pretty far into each other so when they try to rebound it just gets stuck...
Here's the formula for what I did before (doesn't work very well):
diff = pos2 - pos1
if(pos1 < pos2){
pos1 = pos1 + ((diff - r)/2)
pos2 = pos2 - ((dif - r)/2)
}else if(pos2 > pos1){
pos1 = pos1 + ((diff + r)/2)
pos2 = pos2 - ((dif + r)/2)
}
pos1 is the position of one circle
pos2 is the position of another circle
diff is the difference between positions
r is the radius
it divides by 2 to space them equally.
When I try this in my project it doesn't work. Both the circles move with each other in a weird vibrating motion...
Any help will get +1 rep thanks!
It would be easy to just do velocity = -velocity but the objects move fast so when the collide they get pretty far into each other so when they try to rebound it just gets stuck...
Here's the formula for what I did before (doesn't work very well):
diff = pos2 - pos1
if(pos1 < pos2){
pos1 = pos1 + ((diff - r)/2)
pos2 = pos2 - ((dif - r)/2)
}else if(pos2 > pos1){
pos1 = pos1 + ((diff + r)/2)
pos2 = pos2 - ((dif + r)/2)
}
pos1 is the position of one circle
pos2 is the position of another circle
diff is the difference between positions
r is the radius
it divides by 2 to space them equally.
When I try this in my project it doesn't work. Both the circles move with each other in a weird vibrating motion...
Any help will get +1 rep thanks!