We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do I check if a shape is touching another shape in p5? I tried something like this:
if (shape1.x && shape1.y === shape2.x && shape2.y) {
//other code
}
but it doesn't work.
Answers
It really depends on what kinda shape your talking about, for circles you can use the dist and check the distance between the two shapes with something like this
But to really help I have to know shapes your using
Common Questions collision detection:
https://forum.processing.org/two/discussion/23052/collision-detection
I'm using two circles, one circle can move, the other one can't. I want to see if the first circle is touching the other so then I can do something with the second one.
From the guide that @koogs linked to in the FAQ, there is an entry "circle/circle":
http://www.jeffreythompson.org/collision-detection/circle-circle.php
When I did some simple collision detection in C++ it looked like this. You can apply the same logic BUT, I am not familiar enough with P5js yet to offer a more "built-in" alternative such as distance metrics using dist()
My Pseudo:
Essentially you derive the points or vectors you would like to compare (x, y)
leftV / rightV - implies x
topV / bottomV - implies y
@Mostly_Yoshi -- @Nautilus requested circle-circle collision detection, but you gave the example of rectangle-rectangle collision detection. That won't work here.
@jeremydouglass true, its certainly not optimal for elliptical shapes. The idea is still apparent I suppose.