We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey Sages,
I'm trying to make a game in which an image (a humanoid figure) can be flown through space to grab a circular gem. The figure can be accelerated and rotated as it moves. The figure's hand includes a "hit circle" centered on the hand with a given diameter. When the hit circle collides with the gem, the gem should disappear.
The following code gives me a hit circle which positions correctly as the figure moves and rotates. (The hand is to the right and below the center of the image at setup.)
imageMode(CENTER); pushMatrix(); translate(figX, figY); rotate(radians(figAng)); image (figViz, 0, 0); ellipse(handX, handY, handDia, handDia); popMatrix();
I was doing fine until I tried to use dist() to check for a collision:
if (dist(figX + handX, figY + handY, gemX, gemY) < gemDia/2 + handDia/2 ) { gotGem = true; println("Huzzah!"); }
This does not produce a collision whether I check within the push/popMatrix() code or outside of that code. Can anyone suggest what I am doing incorrectly or direct me to some resource that explains how to detect collisions between circles when one is being rotated around an exterior point?
Thanks much, L
Answers
Fantastic - thanks so much! I didn't know about screenX/Y() or the syntax you use for the boolean, but your code lays it out so clearly I was able to connect all the dots. Will report back on the implementation.