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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:12:31+00:00 2026-05-22T19:12:31+00:00

I try to create a very simple physics engine for my study (processing used

  • 0

I try to create a very simple physics engine for my study (processing used for a interactive installation).

The target is to have a ground covered with balls that you can throw around with gestures (based on Kinect information).

Therefor I need to do some basic physic simulation like bouncing and thats what I started with. So there are just balls falling down and bouncing. I simulated the air resistance with a simple 0.995f multiplication on the speed if the ball moves up. Works nice and looks realistic. The main problem is, that the balls never stay calm on the ground. Instead they start to tremble on the ground. That means there is a movement of 1 or 2 pixels up and down.

How can I prevent that without implementing some “borders” on which I set the position directly to the bottom and the speed to zero?

My applet:

public class BubblePhysicApplet extends PApplet {
    public static int width = 640;
    public static int height = 480;
    long lastTime = -1;
    Bubble[] mBubbles = new Bubble[10];
    Random mRandom = new Random();

    public void setup() {
//      size(width, height, OPENGL);
        size(width, height, P2D);
        for (int i = 0; i < mBubbles.length; i++) {
            mBubbles[i] = new Bubble(mRandom.nextInt(width), mRandom.nextInt(height), 50);
        }
        lastTime = System.currentTimeMillis();
    }

    public void draw() {
        background(0);
        long tmp = System.currentTimeMillis();
        long elapsed = tmp - lastTime;
        for (Bubble bubble : mBubbles) {
            bubble.animate(elapsed);
            bubble.draw(this);
        }
        lastTime = System.currentTimeMillis();
    }
}

The ball/bubble:

public class Bubble {
    float mX;
    float mY;
    float mSize;
    float mSpeedX = 0;
    float mSpeedY = 0;

    public Bubble(int x, int y, int size) {
        mX = x;
        mY = y;
        mSize = size;
    }

    public void draw(PApplet applet) {
        applet.stroke(255);
        applet.noFill();
        applet.ellipseMode(PApplet.CENTER);
        applet.ellipse(mX, mY, mSize, mSize);
    }

    public void animate(long elapsed) {
        updateSpeedY(elapsed);
        if (mSpeedX != 0 || mSpeedY != 0) {
            checkBorders();
        }
    }

    private void checkBorders() {
        if (mY > BubblePhysicApplet.height - mSize / 2) {
            mY = 2 * BubblePhysicApplet.height - (mY + mSize);
            mSpeedY = -mSpeedY;
        }
        if (mX > BubblePhysicApplet.width) {
            mX = BubblePhysicApplet.width - (mX - BubblePhysicApplet.width);
            mSpeedX = -mSpeedX;
        }
    }

    private void updateSpeedX() {

    }

    private void updateSpeedY(long elapsed) {
        mSpeedY += (elapsed / 1000f) * 9.81f;
        if (mSpeedY < 0) {
            mSpeedY *= 0.95f;
        }

        mY += mSpeedY;
    }
}
  • 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-22T19:12:31+00:00Added an answer on May 22, 2026 at 7:12 pm

    It’s not only air resistance that slows the ball down, but the fact that it’s not perfectly elastic as this line suggests: mSpeedY = -mSpeedY;

    The ball absorbs energy when it squishes against the floor before it bounces back, so it doesn’t bounce as high. Try a real super ball. I seem to remember it only bounces 80% as high or so. You might try:
    mSpeedY = – (0.8 * mSpeedY);

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

Sidebar

Related Questions

I try to create a very simple app using windows API. I've done some
I used to go back and edit my Mercurial commits to try to create
I have a COM dll written in vb6. When I try to create a
I was asked to create a very simple dashboard using a Sharepoint list as
I am trying to create a very simple chat window that simply has the
I have a very simple VB.net Windows Service written using VS.net 2008. The program
I have a very simple Excel Addin build it in Visual Studio 2008 for
I am trying to create a very simple help page in my app. The
I have a very simple class that opens a file and creates a memory
I have two separate projects ( comclient and comserver ), with some very simple

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.