Note that there are some explanatory texts on larger screens.

plurals
  1. POCollision Response between a static and dynamic circle
    primarykey
    data
    text
    <p>This is developed in JavaFX.</p> <p>There are 2 balls - a dynamic ball and a stationary one. The first ball(dynamic) bounces off the walls and anything that comes in its way.</p> <p>The second ball's purpose is to be an obstacle for the first ball. So, whenever the first ball touches the second ball, the first ball should instantly bounce away. Currently, the bouncing has very bad accuracy, and I don't know exactly how to fix it. Sometimes the first ball will bounce properly, but usually it will go <strong>INSIDE</strong> the second ball, get stuck in there for a moment, and then bounce away. The picture below goes over this exact issue. <img src="https://i.stack.imgur.com/RrnAF.png" alt="enter image description here"> </p> <p>Here's my code for detecting collision and responding to it:</p> <pre><code> //Pythagorean Theorem, to detect collision, by estimating the distance between the two circles double dx = circle.getLayoutX() - circle2.getLayoutX(); double dy = circle.getLayoutY() - circle2.getLayoutY(); double radii = circle.getRadius() + circle2.getRadius(); double distance = (dx * dx) + (dy * dy); double minDistance = radii * radii; // I believe something is missing in the lines below, which is causing the problem. if (distance &lt; minDistance) { //If circle1(dynamic) collides with circle2(stationary) c1SpeedX = c1SpeedX * -1; //Inverts direction. } </code></pre> <p>I spent hours on google, but I was not able to find an answer. I hope somebody can provide a solution and explain the issue. Thanks a lot in advance everybody!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload