[SOLVED]Strange Behavior from setPos

I could have the wrong logcial understanding of setPos, but…

When you have a Node (object) and you call self.Object.setPos(0,0,0)…

Is that setting position or origin? The reason I ask this now is because, up until now I have been using setPos to set the position of nodes in the world and it has worked correctly.

But now lets add some children to that Node making it a parent Node. I now call self.Object.setPos(0,0,0) and instead of setting the Parent Object’s position I have in fact moved a node’s origin!! Which one? Parent or child? Good question. From what I can tell…looks like my child node’s origin got moved.

I always thought calling something like self.Object.setPos(render, 0, 20, 0) would set the origin; and setting the origin of children nodes as…self.ChildObj.setPos(self.Object, 0, -30, 0).

I was calling self.Object.setPos(0,0,0) mostly, that’s why I didn’t notice an origin change and the object was setting to this position in the level (and childred), but when I tried self.Object.setPos(0, 3000, 0) I got the nasty surprise of origin change.

Since P3D has a scene grapch concept, you would think moving the parent Node would in fact move any children nodes just the same…but it was clear to me…something was offset.

Let me add, I never had an offset like that while calling setPos on a Node that was not a parent.

Clearly…I have moved off the logical path of understanding the setPos.

So, someone…if you don’t mind, set me back on the straight path. :slight_smile:


Got my config.exe file all figured out. I just need to give it a GUI now. So, when a player starts the game, they will set the game’s configuration first, then play. You see that kind of setup more and more now. This is good for P3D because changing resolution during gameplay will show your desktop and knock you out of full screen mode; I have never been able to get back into true full screen after that. Setting resolution before hand ends that issue.

The Vamprye Story configs the game from within then pops up a message saying a restart is needed. Why make the player exit and restart the game again? When you could have allowed them to configure the game from the start… :wink:

If I understand you correctly then you have indeed misunderstood.

As best I understand it:

Calling “setPos” sets an object’s position, and specifically sets its position relative to its parent object. In a sense the parent object’s position is the “origin” for its children. Thus when you call “setPos” on an object that has children, you move it and thus move the “origin” of its children.

Think the scene graph as something like a multi-level hanging mobile, like this, with each level of the mobile being an object in the scene graph. Calling “setPos” analogises to unhooking the object in question: it allows one to move the object, but also implicitly moves the objects below it, keeping their positions relative to their parents.

On the other hand, calling “setPos” with another NodePath as an argument – as in “setPos(render, 0, 0, 0)” – moves the object – and again, anything below it – to the given position relative to the specified NodePath. It doesn’t change the origin-point of the NodePath.

Then what I experienced was indeed an unexpected engine output.
I’m going to keep an eye on that as I continue to use P3D.

Simple pre-game configuration gui:

In that case, could you please elaborate on what you meant by the following section?

What, precisely, happened? What do you mean by having “moved a node’s origin”? The origin of a node should just be the position of its parent node. Perhaps a few screenshots of what you’re seeing, along with a brief summary of the relevant hierarchy of nodes, might help.

As I typed… When calling setPos(0,0,0) on a Parent Node (with children nodes), the child node appeared to be offset from the Parent…or at least it seemed to be the child node; it can be hard to tell because the Parent is just an empty node as in: self.Pobject = NodePath(PandaNode(‘PrntObj’))

I could tell there was an offset because other objects that were moving towards the particular Instance in question were stopping at that Instance, but the visual part of that Instance, the child node, was sitting way off from the where it should have been. That shouldn’t have happened; not just from calling setPos() on the Parent.

The child and Parent should act as one.

The scenario you describe is impossible. You are misunderstanding the relationships the nodes have, or how you are moving them.

Try using render.ls() to see what the scene graph looks like and make sure it conforms to the mental model you have of it. Either the child nodes with the visible geometry have their own positions in local space, the models themselves are not centred around the origin, or whatever code you’re using to move objects towards it is wrong.

“Nope…” Everything is fine there. :slight_smile: I do agree with you though… That’s impossible…one would think anyway…

But it happened. :laughing:

----Update-----

The thought just hit me… I think I know what happened now. :smiley:

Would you mind sharing what the problem was? I’m quite curious, I’ll admit!