Acceleration doesn't affect Velocity
in
Programming Questions
•
2 months ago
Hello
Im just working on Daniel Shiffman's Nature of Code book and I have the following problem with the exercise 1.8.
I have an object (ellipse) which should move towards the cursor mouse. My Problem is now that I don't know how to control the speed of my object. The object should move faster when it is farther away but my object is just keeping the same speed all the time. How can i control this by changing only the acceleration? I know it has to do something with the distance between these two points.
Here is my small update Code in my object:
Here is my small update Code in my object:
- void update() {
- PVector mouse = new PVector(mouseX, mouseY);
- PVector dir = PVector.sub(mouse, location);
- float mag = dir.mag();
- dir.normalize(); //now we have just the direction to the mouse
- acceleration = dir;
- velocity.add(acceleration);
- velocity.limit(3);
- location.add(velocity);
- }
1