It looks like PhysicsEngine in game,about the
collision detection.
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
Last month,[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
I had the same problem as you .Now,i still not solve this problem,i think that it surely not easy.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
If the thing is ball,you can use my code.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
I'm not sure this will help you a lot.But ,we are in the same problem ,i'm very happy to share that.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
This code use the ActionScript in Adobe Flash.[/font]
There are two balls,one called ball,the other is balll.(not the same).
function onEnterFrame(e:Event)
{
ball.y += ball.vy;
ball.x += ball.vx;
balll.x += balll.vx;
balll.y += balll.vy;
sina = (ball.y - balll.y)/(ball.radius + balll.radius); //their sin corner and cos corner (Rectangle Function)
cosa = (ball.x - balll.x)/(ball.radius + balll.radius);
distance = Math.sqrt((ball.x - balll.x)*(ball.x - balll.x) +(ball.y - balll.y)*(ball.y - balll.y)); //this is the distance between two balls
if (distance <= ball.radius +balll.radius)
{
double v;
v = Math.sqrt(ball.vx * balll.vx + ball.vy * balll.vy);
ball.vx = (v * cosa);
ball.vy = (v * sina);
balll.vx = -(v * cosa);
balll.vy = -(v * sina);
}
}
My problem is that if two balls overlap,the ball will not move , i can't find a good formula to not not let them overlap when "distance == ball.radius+balll.radius",
My idea is
if (distance <= ball.radius +balll.radius)
{
Remove two ball to the position where they crash.//it will be seen that they are not overlap .
.........
}
But i cannot do it!It is still a question.