Author Topic: translation and distance  (Read 818 times)

Offline Minigame

  • int
  • **
  • Posts: 55
    • View Profile
translation and distance
« 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: translation and distance
« Reply #1 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)

but that basically does the same thing.