I'm assuming you have a set of points in 2D space and you simply want to move from one point to the other? Doing this is fairly straightforward, however there is one problem, finding weather or not the object has reached its current point so that it can move towards a new point. This is only a problem for floating point numbers.
You will need this support function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
public static boolean isInFront2(final Vector destination, final Vector current, final Vector direction) { float product = (current.getX() - destination.getX()) * direction.getX() + (current.getY() - destination.getY()) * direction.getY(); return (product > 0.0f); }
public static boolean isInFront3(final Vector destination, final Vector current, final Vector direction) { float product = (current.getX() - destination.getX()) * direction.getX() + (current.getY() - destination.getY()) * direction.getY() + (current.getZ() - destination.getZ()) * direction.getZ(); return (product > 0.0f); }
|
hope that helps