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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:20:46+00:00 2026-05-28T05:20:46+00:00

This is something I’m trying to do for a university assignment and I’m quite

  • 0

This is something I’m trying to do for a university assignment and I’m quite new to it, but I’ve done a lot of reading on the subject. Please could someone to explain, in the simplest terms, how to do what I’m trying to do, so that I can understand what needs to happen?

I have an array of objects, each draw a circle to the screen; I have them bouncing within a bounding box but now I’d like them to collide.

I wrote the method below, which is working… but only just. The balls occasionally get stuck and ‘jitter’ on one another and I have no idea why this is happening. Also, I think I’m checking for more collisions than necessary(?).

void handleObjectCollision() {

for(int i = 0; i < _myBtns.length; i++) {

 if(i != _id) {

    float dx = _myBtns[i].x - x;
    float dy = _myBtns[i].y - y;
    float distance = sqrt(dx*dx + dy*dy);

    if(distance < r * 2) {
      xS = -xS;
      yS = -yS;

      // Debug
      // println("Collision!");
    }

  }

}

A full paste of my class and pertaining segments can be found here: http://pastebin.com/eJawiHAE.

Also, here is an example I’ve been working from, http://processing.org/learning/topics/bouncybubbles.html.

I’m trying to achieve a simple bounce (reversal in speed?), without added physics or using vectors, as I want to be able to understand what’s happening in it’s simplest form, first.

Thank you.

  • 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-28T05:20:47+00:00Added an answer on May 28, 2026 at 5:20 am

    You cannot just reverse the direction in which your object is moving, because the collision may happen almost from behind it, in which case the reversal will put it again in collision course against the object which collided with it. That explains the jitter that you see. You need to consider the direction from which the collision occurred, and adjust your direction vector accordingly, using the related physics formulas for what is known in physics as “elastic collisions”.

    Here, check this out: http://en.wikipedia.org/wiki/Elastic_collision

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

Sidebar

Related Questions

When you have code like this: Something something = new Something(); BlahEntities b =
This is something I've pseudo-solved many times and have never quite found a solution
The evaluation order does matter a lot, so, is this something called non-referential-transparency? int
It may be a noob question but is this something to do with my
I could have sworn i have done this somewhere - im using 2.0 right
So I have something along the lines of this private List<ConcurrentQueue<int>> listOfQueues = new
When I used a new variable something.something or this.something, my code worked when I
Is this something that can be done more efficiently than with a vertex array?
I always thought base.Something was equivalent to ((Parent)this).Something , but apparently that's not the
Is this something I shouldn't try?

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.