• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

#ActualMotorBully

Posted 24 March 2012 - 09:49 PM

It looks like PhysicsEngine in game,about the

collision detection.

Last month,

I had the same problem as you .Now,i still not solve this problem,i think that it surely not easy.

If the thing is ball,you can use my code.

I'm not sure this will help you a lot.But ,we are in the same problem ,i'm very happy to share that.

This code use the ActionScript in Adobe Flash.

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)
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
{
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
{
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.

#1MotorBully

Posted 24 March 2012 - 09:47 PM

It looks like PhysicsEngine in game,about the

collision detection.

Last month,

I had the same problem as you .Now,i still not solve this problem,i think that it surely not easy.

If the thing is ball,you can use my code.

I'm not sure this will help you a lot.But ,we are in the same problem ,i'm very happy to share that.

This code use the ActionScript in Adobe Flash.

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)
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
{
double v;
v = Math.sqrt(ball.vx * balll.vx + ball.vy * balll.vy);

ball.vy *=  0.8;
ball.vx *=  0.4;
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