Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:03:13+00:00 2026-05-25T03:03:13+00:00

I’m trying to separate two circles that are colliding. Thanks to the help of

  • 0

I’m trying to separate two circles that are colliding. Thanks to the help of others, I’m right there!

This is my code:

var totalRadius : Number = _circle1.radius + _circle2.radius;
var x : Number = _circle1.position.x - _circle2.position.x;
var y : Number = _circle1.position.y - _circle2.position.y;

var distanceSquared : Number = (x * x) + (y * y);

if (distanceSquared < totalRadius * totalRadius)
{   
    var distance : Number = Math.sqrt(distanceSquared);

    var separation : Number = totalRadius - distance;

    var unitVectorX : Number = (_circle1.position.x - _circle2.position.x) / distance;
    var unitVectorY : Number = (_circle1.position.y - _circle2.position.y) / distance;

    _circle1.position.x += unitVectorX * (separation / 2);
    _circle1.position.y += unitVectorY * (separation / 2);

    _circle2.position.x -= unitVectorX * (separation / 2);
    _circle2.position.y -= unitVectorY * (separation / 2);
}

It works great if the circles have the same velocity. The problem occurs when they have different velocities and the problem is because I’m splitting the separation evenly (separation / 2) I think!

Everything works perfectly if circle1 has a velocity of 1,0 and circle2 has a velocity of -1,0. The two circles hit each other and stop.

If circle1 has a velocity of 2,0 and circle2 has a velocity of -1,0, the circles gradually move to the right. I imagine this is what’s happening:

frame1:

  • circle1 (99, 100)
  • circle2 (101, 100)

frame2:

  • circle1 (101, 100)
  • circle2 (100, 100)
  • collision detected, corrected position of -0.5 and +0.5 respectively.
  • circle1 (100.5, 100)
  • circle2 (100.5, 100)

frame3:

  • circle1 (102.5, 100)
  • circle2 (99.5, 100)
  • collision detected, corrected position of -1.5 and +1.5 respectively.
  • circle1 (101, 100)
  • circle2 (101, 100)

frame4:

  • circle1 (103, 100)
  • circle2 (100, 100)
  • collision detected, corrected position of -1.5 and +1.5 respectively.
  • circle1 (101.5, 100)
  • circle2 (101.5, 100)

As you can see, both circles are gaining +0.5 to the right because of the difference of velocity.

So finally, my question: How can I factor in their velocity into the equation so that it doesn’t play a factor in their separation?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:03:14+00:00Added an answer on May 25, 2026 at 3:03 am

    You need to calculate the point of impact, rather than just (arbitrarily) moving them both backwards equally.

    A quick search found these links:

    1. http://www.t3hprogrammer.com/research/circle-circle-collision-tutorial#TOC-Static-Circle-Circle-Collision-Dete (the section “Dynamic Circle-Circle Collision”)

    2. http://nonlinear.openspark.com/tutorials/vectors/index.htm (section “Impact, not intersection”)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.