I’m new to processing and I’m trying to move a ball (an ellipse) to the position of where the mouse is clicked but I don’t what it to jump there . I want it to move there at a certain speed .
int golfBallX = 200;
int golfBallY = 150;
final int GOLF_SIZE = 30; // size of the golf
final int SPEED = 10; // the ball should move at this speed
void setup(){
size(500 , 500); //canvas size
}
void draw(){
drawBall();
}
void drawBall(){
fill(255);
ellipse(golfBallX ,golfBallY ,GOLF_SIZE,GOLF_SIZE);
}
void mouseClicked(){
golfBallX = pmouseX;
golfBallY = pmouseY;
}
Notice that the magic is happening inside the simulate() method. The ball is now tracking two positions. One is the ball’s current position, cp. The other is the ball’s target position, tp. To simulate movement, each frame, it finds the vector that is the direction, d, that points from the current position to the target position. It then limits this vector to the length of s, the speed of the ball, and uses it to update the current position.