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

Thread: Help on calculating 3d distances

  1. #1
    Lurker lucasmontec is on a distinguished road lucasmontec's Avatar
    Join Date
    Dec 2007
    Posts
    104

    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 is on a distinguished road d3cr1pt0r's Avatar
    Join Date
    Jul 2008
    Posts
    566

    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
    A Hologram
    McLovin is a jewel in the rough McLovin is a jewel in the rough McLovin is a jewel in the rough McLovin is a jewel in the rough McLovin's Avatar
    Join Date
    Sep 2008
    Location
    NY US
    Posts
    1,029
    Blog Entries
    2

    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()
    
    Filipe - you never know what ends up in your love hole
    Poonage - It's not a disorder, it can be solved
    Drunkie - vista was on the trail of complete beauty and perfection
    Omicron - cable management is for losers, and people who know what they're doing
    Drunkie - me and solece have tickets to go see justin bieber, i'm looking forward to it
    JatGoodwin - I don't normally suck dick, but when I do they call me immibis
    Drunkie - THERE IS SIMPLY NOT ENOUGH DICKS
    JatGoodwin - stand back, im going to do science

  4. #4
    Wire Sofaking d3cr1pt0r is on a distinguished road d3cr1pt0r's Avatar
    Join Date
    Jul 2008
    Posts
    566

    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
    Lurker Whodunnit will become famous soon enough Whodunnit's Avatar
    Join Date
    Jan 2008
    Location
    New Zealand, Ackl
    Posts
    655

    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 12:06 AM.
    ЗАГРУЗКА...................

  6. #6
    Bug Buster

    TomyLobo has a spectacular aura about TomyLobo has a spectacular aura about TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,786

    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 will become famous soon enough Nicolai1's Avatar
    Join Date
    Nov 2008
    Location
    Denmark.
    Posts
    1,303

    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
    hat full of head

    Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael's Avatar
    Join Date
    Aug 2007
    Posts
    1,947

    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:
    E2 Code:
    1. VectorDistance = (Him:pos() - You:pos()):length()

  9. #9
    Lurker Whodunnit will become famous soon enough Whodunnit's Avatar
    Join Date
    Jan 2008
    Location
    New Zealand, Ackl
    Posts
    655

    Default Re: Help on calculating 3d distances

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

  10. #10
    Expressionism 2.0

    Syranide has disabled reputation Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,504

    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 1 2 LastLast

Similar Threads

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

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