Hello everyone, i’m new here
I want to make a slingshot that throws projectiles but i’m confronted to a problem with vector.
The objectiv is to have a vector that stores the datas of the throw. “v3”
Can you tell me why my vectors are the same after the first throw ?
My code with vectors
PVector v1, v2;
void setup () {
v1 = new PVector();
v2 = new PVector();
size(400, 400);
}
void draw() {
background(255);
if (mousePressed) line(v1.x, v1.y, mouseX, mouseY);
}
void mousePressed() {
v1.set(mouseX, mouseY);
}
void mouseReleased() {
v2.set(mouseX, mouseY);
print("v1 ", v1.x, ",", v1.y);
print(" v2 ", v2.x, ",", v2.y);
v1 = v2.sub(v1);
println(" v3 ", v1.x, ",", v1.y);
}
The first three throws of the slingshot
v1 132.0 , 185.0 v2 195.0 , 233.0 v3 63.0 , 48.0
v1 159.0 , 225.0 v2 159.0 , 225.0 v3 0.0 , 0.0
v1 245.0 , 205.0 v2 245.0 , 205.0 v3 0.0 , 0.0