object position in world

hey again ppl

i’m trying to get the position of an object in the world (the game). because of the way the classes are arranged in the code, i don’t see any way to pass the nodepath of the object to the other class which needs it. here comes the question:
is it possible to get the position of an object at any time in the gameloop from anywhere? in other words, can one query the scenegraph at any point in the game to obtain the position or nodepath or whatever of an object as long as you know it’s name?

i know this can be fixed if the code was organized in such a way that these objects were global variables but at the moment they aren’t :stuck_out_tongue:

any ideas?

There is a manual page about this: Searching the Scene Graph. This can be made easier by setting appropriate tags beforehand.

Still, better orginization is almost always a good idea. The sooner the easier.

are there instructions somewhere on how to make tags for objects so they can be searched later?


What do you mean with ‘make tags from objects’?
You can stuff the path in a string, if thats what you mean:


i was referring to what cyan said, that it would be made easier by setting appropriate tags beforehand so they can then be used when searching for the position of those objects…

Adding the tags to the scene requires adding them to the egg file. This process is specific to whatever modeling package you are using to fabricate your eggs; I am aware of a script in Maya to do this, but my knowledge of other modeling tools is limited.

If you are using maya to construct your eggs, I believe that a search of the Pipeline forum for “maya tag” may yield results. If it doesn’t, let us know and I’ll see if I can dig up some .mel script to do what you desire.

Another option is to insert the tag directly into the egg file itself; look into the egg syntax document to see the proper format and position for that.

You can add them programatically at runtime.

the people who are making our graphics are making them in 3dsmax and then exporting them to .egg

Try setTag() on your nodepath.

see http://www.panda3d.org/manual/index.php/Common_State_Changes for tag basics and
http://www.panda3d.org/manual/index.php/Clicking_on_3D_Objects for an example using tags programatically.

i’m gonna try the setTag() thing.

just realized that making the tag in 3dsmax wouldn’t work anyway because there are two entities which are loaded from the same model but what i want is that they are both aware of where the other is positioned in the world

ie. 2 submarines (loaded with the same model). both should have some way of knowing where the other sub is in the world.

as i said, i’ll try the setTag thing…but if anyone else has any other ideas don’t hesitate! :smiley:

You CAN get a nodepath from any class in your code that is defined in another class of your code…

If you do something like this:

(pseudo-code style)

class fu()

    self.bar = bar()

class bar()

    self.model = loader.loadModel()

You could also pass the nodepath as an argument to the other class or whatever…

however, there’re certain ways to get your nodepath from anywhere in your code that are easier than searching through the whole nodePath!

what i’ve done is created a torpedo with the torpedo class and i want it to go towards one of the players so it needs the player’s position in every step of the game.

targetPlayer = render.find("**/")

i’ve done just prior to creating the torpedo from the submarine, that replacing modelname with the name of the submarine model, and then when i create the torpedo i pass targetPlayer to the torpedo class

in torpedo before i do any movement i try to do


where target is the argument passed on and is equal to targetPlayer (ie. it should look at the targetPlayer who’s nodepath was hopefully passed on in the beginning

when i run it however, there are error msgs.

“NodePath”, line 5005, in __overloaded_lookAt_ptrNodePath_ptrConstNodePath
AssertionError: _error_type == ET_ok && other._error_type == ET_ok at line 645 of panda/src/pgraph/nodePath.cxx


any ideas

forgot to reply to Legion :stuck_out_tongue:

i know you can do that but what if you want to find out where foo is in the world from inside bar. that is my problem

btw pls look at previous post :slight_smile:

hey all

figured it out. the problem was that i was also loading another object using the same model so it must’ve gotten confused…or something!

thanks for the help tho :smiley: