Advertisement Jump to content
Sign in to follow this  

Is there any master be good at Actionscript in Flash ?

This topic is 2489 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Collision Detection is very important to the Flash!
Now , i have been making a game about basketball,but there is a big skill problem blocked my game development which is about the collision detection algorithm of two balls.
I have defined the name "ball" and "balll".They are all from Ball Class.Ball Class have got the Attribute ,such as ball.vx,ball.vy,ball.radius,ball.v;

Here is my code

sina = (ball.y - balll.y)/(ball.radius + balll.radius);
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));
if (distance <= (ball.radius +balll.radius))
v = Math.sqrt(ball.vx * balll.vx + ball.vy * balll.vy);
ball.x = balll.x+cosa*(ball.radius+balll.radius);
ball.y = balll.y+sina*(ball.radius+balll.radius);
ball.vy *= 0.8;
ball.vx *= 0.4;
ball.vx = (v * cosa);
ball.vy = (v * sina);
balll.vx = -(v * cosa);
balll.vy = -(v * sina);

Now , if the speed of ball is so fast , two ball will l overlapped together and they will not move or move slowly.How can i solve this problem?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!