I have been trying to figure out how to determine the distance between vector A and vector B, then use the result to determine if it is within a certain range in world space.
I have experimented and tried many various attempts for some time but.. ???
Here's an example of code representing what my overall goal would be (1 of many failed attempts)
float distanceToDestination = localPlayer.getTransformedCenter().calcSub(dest).length(); // XXX
if (distanceToDestination <= 100) {
// Here, I would translate the local player in my game <distanceToDestination> world units.
}
I've tried a lot of different solutions and I'm not really that great with these type of mathematics so any help is very much appreciated
What's wrong with that attempt? It looks fine to me assuming that dest ist filled with some reasonable values. Another option is to simply use
http://www.jpct.net/doc/com/threed/jpct/SimpleVector.html#distance(com.threed.jpct.SimpleVector) (http://www.jpct.net/doc/com/threed/jpct/SimpleVector.html#distance(com.threed.jpct.SimpleVector))
but that basically does the same thing.