+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Help on calculating 3d distances

  1. #1
    Wirererer lucasmontec's Avatar
    Join Date
    Dec 2007
    Posts
    114

    Default Help on calculating 3d distances

    I'm working on a smart HUD helper with the super advanced HUD indicators and i need to calculate the distance between me and an other player using 2 target finders. One target finder would tell my position while the other would tell his (in X Y Z), than ill get the distance between us and show in the adv HUD indicator.

    Probably its an easy formula...

  2. #2
    Wire Sofaking d3cr1pt0r's Avatar
    Join Date
    Jul 2008
    Posts
    553

    Default Re: Help on calculating 3d distances

    Make an expression2 like this:

    Code:
    @name 
    @inputs You:entity Him:entity
    @outputs VectorDistance:vector
    @persist X Y Z
    X = abs(Him:pos():x() - You:pos():x())
    Y = abs(Him:pos():y() - You:pos():y())
    Z = abs(Him:pos():z() - You:pos():z())
    
    VectorDistance = vec(X,Y,Z)
    Wire You:entity and Him:entity to 2 target finders.
    <3

  3. #3
    ◕␣◕ McLovin's Avatar
    Join Date
    Sep 2008
    Location
    Batman, Turkey
    Posts
    2,331
    Blog Entries
    3

    Default Re: Help on calculating 3d distances

    Just wire Tar1 to the first target finder for Target1 and Tar2 to target finder for Target2.
    Code:
    @name Target Calculator
    @inputs Tar1:entity Tar2:entity
    @outputs Xo Yo Zo
    @persists Vec:vector
    interval(10)
    Vec = Tar1:pos() - Tar2:pos()
    Xo = Vec:x()
    Yo = Vec:y()
    Zo = Vec:z()
    Anticept - HP you are terrible at trolling. Always have been. Leave it up to the pros like Jat.
    Black Phoenix - Actually cunt goes into bullshit. Bullshit does not fit in cunt.
    Drunkie - Logically, Jat Goodwin must be a fist pumping guido.

  4. #4
    Wire Sofaking d3cr1pt0r's Avatar
    Join Date
    Jul 2008
    Posts
    553

    Default Re: Help on calculating 3d distances

    Quote Originally Posted by IamMcLovin View Post
    Just wire Tar1 to the first target finder for Target1 and Tar2 to target finder for Target2.
    Code:
    @name Target Calculator
    @inputs Tar1:entity Tar2:entity
    @outputs Xo Yo Zo
    @persists Vec:vector
    interval(10)
    Vec = Tar1:pos() - Tar2:pos()
    Xo = Vec:x()
    Yo = Vec:y()
    Zo = Vec:z()
    He will get negative distance outputs that way. Use abs() to avoid negativity
    <3

  5. #5
    Wire Sofaking Whodunnit's Avatar
    Join Date
    Jan 2008
    Location
    New Zealand, Ackl
    Posts
    636

    Default Re: Help on calculating 3d distances

    erm magnitude of a vector between two points is:

    ((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)^.5


    the other suggestions are incorrect... they found the direction vector between you and enemy , then abs'd them which probably fucks it up( inverts the vector componants if they are negative, if you ever reused them they might be incorrect for other applications), then they didnt even find the magnitude of it to give you a distance value.

    you could just use the vector length function anyway....

    Code:
    @name Target Calculator
    @inputs Tar1:entity Tar2:entity
    @outputs Distance
    @persists Vec:vector
    Vec = Tar1:pos() - Tar2:pos()
    Distance = Vec:length()
    finally, if you wanted the individual componants , dont abs the z value because its useful to see if he is above or below you.
    Last edited by Whodunnit; 03-08-2009 at 01:06 AM.
    ЗАГРУЗКА...................

  6. #6
    Bug Buster TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,796

    Default Re: Help on calculating 3d distances

    even shorter:
    Code:
    @name Target Calculator
    @inputs Tar1:entity Tar2:entity
    @outputs Distance
    @persists Vec:vector
    Distance = Tar1:pos():distance(Tar2:pos())

  7. #7
    Banned Nicolai1's Avatar
    Join Date
    Nov 2008
    Location
    Denmark.
    Posts
    1,251

    Default Re: Help on calculating 3d distances

    Quote Originally Posted by TomyLobo View Post
    even shorter:
    Code:
    @name Target Calculator
    @inputs Tar1:entity Tar2:entity
    @outputs Distance
    @persists Vec:vector
    Distance = Tar1:pos():distance(Tar2:pos())
    You forgot interval

  8. #8
    Wire Sofaking Azrael's Avatar
    Join Date
    Aug 2007
    Posts
    1,946

    Default Re: Help on calculating 3d distances

    Quote Originally Posted by d3cr1pt0r View Post
    Code:
    @name 
    @inputs You:entity Him:entity
    @outputs VectorDistance:vector
    @persist X Y Z
    X = abs(Him:pos():x() - You:pos():x())
    Y = abs(Him:pos():y() - You:pos():y())
    Z = abs(Him:pos():z() - You:pos():z())
    
    VectorDistance = vec(X,Y,Z)
    You're doing it completely wrong. That doesn't return the distance, that returns the difference between them. Here's what you'd want to do:
    [highlight=E2]VectorDistance = (Himos() - Youos()):length()[/highlight]

  9. #9
    Wire Sofaking Whodunnit's Avatar
    Join Date
    Jan 2008
    Location
    New Zealand, Ackl
    Posts
    636

    Default Re: Help on calculating 3d distances

    interval is unnecessary for this....
    ЗАГРУЗКА...................

  10. #10
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default Re: Help on calculating 3d distances

    Quote Originally Posted by Nicolai1 View Post
    You forgot interval
    interval is only if you want to do something that is _independent_ of inputs, this is highly dependent on inputs, no point in interval.

    Quote Originally Posted by Whodunnit View Post
    interval is unnecessary for this....
    exactly.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Need help with calculating velocity of a vector
    By ace1313 in forum Expression 2 Discussion & Help
    Replies: 3
    Last Post: 03-07-2009, 03:54 AM
  2. Need Help Calculating Yaw & Pitch From 2 XYZ coordinates
    By Meatloaftwo in forum Installation and Malfunctions Support
    Replies: 16
    Last Post: 10-20-2008, 10:19 AM
  3. Calculating Bearing, Elevation, and Distance with vectors
    By GhostMX in forum Installation and Malfunctions Support
    Replies: 8
    Last Post: 08-11-2008, 02:20 PM
  4. Calculating bearing?
    By thesage1014 in forum Installation and Malfunctions Support
    Replies: 7
    Last Post: 08-19-2007, 11:32 PM
  5. Calculating Bearing and Elevation from GPS co-ords
    By MistaGiggles in forum Installation and Malfunctions Support
    Replies: 4
    Last Post: 06-06-2007, 12:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots