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 6378059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:57:18+00:00 2026-05-25T01:57:18+00:00

I’m trying to normalize the distance between two balls once a collision has been

  • 0

I’m trying to normalize the distance between two balls once a collision has been detected

the collision detection

do_shapes_collide: function(shape1,shape2)
{
    var reach1 = shape1.radius + shape1.velocity() + vr.o.border_width;
    var reach2 = shape2.radius + shape2.velocity() + vr.o.border_width;

    var distance = vr.distance(shape1, shape2);

    return distance < reach1 + reach2;

},

so once we’ve determined these sphere’s are colliding, I need to reset their distance from each other… I’m getting flashbacks to my days in algebra class with point/slope formula’s etc…

I’ve got the required distance that needs to exist between them and (what I believe to be) the angle of collision.

I need to set shape x/y on the on the angle of collision.

drawing a blank on what I should do from here to set shape‘s x and y…

if (vr.do_shapes_collide(shape, next_shape))
{
    var req_distance = shape.radius + next_shape.radius + (vr.o.border_width * 2);
    var slope = (shape.y - next_shape.y) / (shape.x - next_shape.x);
    shape.x = 
    shape.y =
}
  • 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-25T01:57:19+00:00Added an answer on May 25, 2026 at 1:57 am

    Think vectors. If you’ve got the two shapes are overlapping, you’ve got a vector from the center of one to the center of the other like so (this only makes sense after adding their velocities to their positions, since that’s when they’ll overlap):

    var diff = {
        x: next_shape.x - shape.x,
        y: next_shape.y - shape.y
    };
    

    That’s the vector from shape to next_shape. And it has less magnitude (it’s shorter) than it needs to be for the shapes to stay apart. So to find the amount the shapes need to move

    var diff_magnitude = Math.sqrt(diff.x*diff.x + diff.y*diff.y);
    var overlap = (req_distance - diff_magnitude) / 2; // each shape needs to move this distance
    

    Now scale the diff vector to the match that distance/magnitude

    diff.x = overlap * diff.x / diff_magnitude;
    diff.y = overlap * diff.y / diff_magnitude;
    

    An finally, move one shape in one direction, and the other shape in the opposite direction

    shape.x -= diff.x;
    shape.y -= diff.y;
    next_shape.x += diff.x;
    next_shape.y += diff.y;
    

    The two shapes should now be just up against each other.

    You’ll also want to set their velocities to be in the positive/negative direction of diff, so they continue on that trajectory after the collision, if indeed they maintain their velocities.

    Note that this doesn’t really “bounce” the shapes off each other, but only moves them away enough to resolve the overlap that exists after they’ve begun to overlap. So it’s rather simplistic. But there are ton of sources that’ll give you more precise methods for collision detection and collision response.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.