[LUA] Node location

Discussion in 'Programming' started by Funky7Monkey, Mar 4, 2015.

  1. Funky7Monkey

    Funky7Monkey
    Expand Collapse

    Joined:
    Oct 12, 2014
    Messages:
    977
    Is there any way to retrieve the location of a specific node (relative to the map origin)? For, say, use in a UI app.
     
  2. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,683
    You can get the entire vehicle position with obj:getPosition(). But there is no way to get the node position from the physics. (as far as I know)

    You can get the node position in the JBeam but it will not correspond to it's position in the world
    Code:
    for k,v in pairs(v.data.nodes) do
       print("pos: " .. v.x .. " " .. v.y .. " " .. v.z)
    end
    
    EDIT: 5 years later we can now do this. I forget whether the function is called obj:getNodePos or obj:getNodePosition. The input is the node cid (not the name)
     
    #2 Dummiesman, Mar 4, 2015
    Last edited: Jan 26, 2020
    • Informative Informative x 3
  3. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    Thanks for the info on this @Dummiesman. I tried what you posted in your update and I'm afraid that you still can't directly get a location for a node relative to the map origin, even using getNodePosition().

    As far as I can tell, that's not a big problem though. I've just been adding the (relative) node position to the (absolute) vehicle position. Convert both to vec3 and just do an addition operation. Signing (negative/positive) gets handled automatically. This seems to be an OK technique. I'd be interested to hear about it if I'm doing something bad though!

    Code:
    local searchNodeName = "fw1l"
    local searchNodePos
    
    for k,v in pairs(v.data.nodes) do
      if v.name == searchNodeName then
        searchNodePos = vec3(obj:getPosition()) + vec3(obj:getNodePosition(v.cid))
      end
    end
    
    dump(searchNodePos)
    
     
    • Like Like x 1
  4. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,683
    getNodePosition gets the node position relative to the vehicles location, so that would be the correct way to get it in world space :)
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice