Yesterday’s post looked at vectors between two objects. Taking their x and y differences enabled us to derive the magnitude of vectors pointing to either one. The deceleration example in “Java Game Programming for Dummies” uses the dx and dy values of the existing vector before subtracting a scaled unit vector from it. With only one object, how do we find the vector?
We can project the object’s next position because we know its dx and dy values. We know that the object’s next position will be a new x- and y-coordinate that is dx values away across and dy values up or down (depending on sign). This ghost object is our second point.
Instead of adding the vector to exhibit repulsion behavior, the book’s example subtracts from the original vector. This leads to deceleration.
So things are nicely consistent conceptually. Using images is two chapters away!