Need Simple Colision Example

Hy, I need a code for a ball that’s controlled by the mouse that when it hits any of the corners the ball goes back to the middle, thank you!

We are glad to help you if you have problems getting your Code to run, or don’t know how to do something, but please try it yourself first, but obviously we still can direct you to the right answer, so that you can achive it yourself and therefore learn and improve your problem-solving and Processing skills.
To make what you what, you just need to create a circle for the ball, which can be done with ellipse(x, y, width, height). Then you can move the ball either using translate(x, y) to move it. You can also get the x and y coordinates of the mouse by using the mouseX and mouseY variables respectively. Then you just need to check if the position of the ball is outside the bounds of your sketch in this case, or a rectangle in general. This can be done by checking if the x or y position of your ball is bigger than the size of your sketch, or smaller than 0 in your case. And if it is, then set the position of the ball to where you want it to be. In your case width/2, height/2.
Hope this helps :blush:


Shameless self-promotion: here is a tutorial on collision detection in Processing:


Like @Lexyth is saying, you have to try to do something. The reason is that it gives a good indication of your skill level. And what you want/what you want to achieve. There are many ways to solve a problem.

If I were you I would start by coding a ball, or an ellipse.
And then try to figure out how to controll it with the mouse. And then how to do the collision detection.