PVector basic trouble
in
Programming Questions
•
1 year ago
Hi everyone,
I've only just begun trying to figure out the PVector class - so this probably has a real simple solution to it ... I can't get the red point to move to mouse location, by using the PVector class. Any suggestions as to what I am doing wrong?
Thanks a bunch in advance!
/Claus
- PVector loc, dir;
- float rad = 75;
- void setup() {
- size(500, 500);
- background(255);
- noCursor();
- // create random point
- loc = new PVector(random(width), random(height));
- dir = new PVector();
- }
- void draw() {
- background(255);
- // random point draw
- stroke(255, 0, 0);
- strokeWeight(10);
- point(loc.x, loc.y);
- // mouse
- noFill();
- stroke(0);
- strokeWeight(10);
- point(mouseX, mouseY);
- if (mousePressed == true) {
- // i create new PVector for mouse location
- PVector mouse = new PVector(mouseX, mouseY);
- // i create a PVector between mouse location and loc
- dir.sub(dir, loc);
- // i add dir to loc - but the point doesn't move???
- loc.add(dir);
- }
- }
1