In Processing, I'm trying to set a sprite's direction and momentum by clicking where to place it, and releasing the mouse to show what direction it should move in, with 0 degrees being directly upwards. However, the atan() function returns weird values, ranging from about 30 degrees to about 60. I've already made sure it's not a problem converting radians/degrees, and I still can't figure it out.
void mousePressed(){
if (ballCount<limit){
ballX[ballCount]=mouseX;
ballY[ballCount]=mouseY;
ball[ballCount]=true;
ballSize[ballCount]=currentSize;
}
}
void mouseReleased(){
if (ballCount<limit){ //This next line is the one I'm having problems with
ballDir[ballCount]=atan((ballX[ballCount]-mouseX)/(ballY[ballCount]-mouseY));
println(degrees((ballDir[ballCount])));
ballCount++;
}
}
Never mind, I found the answer. A different method was running in draw() that would update the ballCount variable based on the amount of balls[] that were true, and so the ballCount variable would differ between mousePressed() and mouseReleased().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.