jPCT - a 3d engine for Java => Support => Topic started by: Minigame on March 10, 2013, 11:49:54 am

Title: translation and distance
Post by: Minigame on March 10, 2013, 11:49:54 am
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)
Code: [Select]
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
Title: Re: translation and distance
Post by: EgonOlsen on March 10, 2013, 09:47:09 pm
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.