0 votes

How do we assign a NodePath to certain property?

I have read it:

NodePath get_as_property_path()

Returns a node path with a colon character (:) prepended, transforming it to a pure property path with no node name (defaults to resolving from the current node).

# This will be parsed as a node path to the "x" property in the "position" node
var node_path = NodePath("position:x")
# This will be parsed as a node path to the "x" component of the "position" property in the current node
var property_path = node_path.get_as_property_path()
print(property_path) # :position:x

Have written the code below: Please give any ideas:

    var node_path = NodePath(".")
    print(node_path)
    var gg = HingeJoint.new()
    add_child(gg)
    **gg.get("nodes/node_a") == node_path [I WANT TO ASSIGN HERE]
    gg.get("nodes/node_b") == NodePath("/root/Node/Player")**
in Engine by (193 points)
edited by

Please give any ideas

Ideas about what? What are you trying to do? What do you expect to happen? What does happen instead?

My savior, https://godotengine.org/qa/user/njamster. Thanks that you are here.

I want to hinge joint 2 objects and separate them afterwards:

        var gg = HingeJoint.new()
        add_child(gg, true)
        node1 = get_node("../Player").get_path()
        print(get_node("./HingeJoint").get("nodes/node_b").get_class())
#       get_node("./HingeJoint").get("nodes/node_b").NodePath = get_node(node1)
#       get_node("./HingeJoint").get("nodes/node_b").get("nodes/node_b")

So far, I joint them with PhysicsServer. But physicsServer doesn't separate them. So I want to create an hingejoint then, you know, get 2 of them defined in the block code.

#       get_node("./HingeJoint").get("nodes/node_b").NodePath = get_node(node1)
#       get_node("./HingeJoint").get("nodes/node_b").get("nodes/node_b")

But it says "cant assign to expression"

2 Answers

+1 vote
Best answer

Here you go:

gg.set("nodes/node_a", self.get_path())
gg.set("nodes/node_b", get_node("/root/Node/Player").get_path())
by (10,255 points)
selected by

You sir remarkable. Do you have youtube account? or anywhere I can follow thee closer Sir

I'm flattered but no, nothing like that. Not yet at least... never say never! ;)

:))) You are ground breaker Sir but more than a miner:)

0 votes

Have done it thanks to https://godotengine.org/qa/user/njamster. There are some people who are more than guiding you. There presence empowers your selfawereness. Thanks https://godotengine.org/qa/user/njamster who has helped us many times and empowers us. Solved by thinking like him:)

export(NodePath) var node1
export (NodePath) var node2

var player_node


func fly_the_kite(player):
    holder = player
    if flied_the_kite:
#       leave_follow_me()
        print("nomore")
        flied_the_kite = false
#       PhysicsServer.joint_create_hinge(get_parent().get_node(str(player)).get_rid(), get_parent().get_node(str(player)).transform, get_node_or_null("Box5").get_rid(), get_node_or_null("Box5").transform)
        Global_batch.carried_object_items.erase(self.name)
        return
    else:
        flied_the_kite = true
        print("nomore2")
#       PhysicsServer.joint_create_hinge(get_parent().get_node(str(player)).get_rid(), get_parent().get_node(str(player)).transform, self.get_rid(), get_parent().get_node(str(player)).transform)
#       follow()

        var gg = HingeJoint.new()
        add_child(gg, true)
        node1 = get_node("../Player").get_path()
        node2 = self.get_path()
        print(get_node("./HingeJoint").get("nodes/node_b"))
        get_node("./HingeJoint").set("nodes/node_a", get_node(node1))
        get_node("./HingeJoint").set("nodes/node_b", get_node(node2))

What I have done, is setting the properties with "set" : get_node("./HingeJoint").set("nodes/node_a", get_node(node1))

Previous code below was not working because it tries to set a fixed property to constant value

get_node("./HingeJoint").get("nodes/node_b").NodePath = get_node(node1)
by (193 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.