Is there a way to get a parent node to follow its children? Or maybe a bi-directional mapping so that if the parent moves, the child follows suit, or if the child moves the parent follows? I basically want to have a parent node be a wrapper for several models, but it will not move if one of its children moves.
How about simply moving the parent instead of the child?
And why do you want the parent to move? Seems like you are trying to use the scene graph for something it is not intended.
Yeah, a common mistake for programming beginners is to try and change the behavior of the libraries / API to implement the functionality they intend for their application. In this case, it would be simpler if you had your own objects that you can move and “bind” together which simply set their locations etc. to the scenegraph so you get a visual representation. This way you can even change the whole visual representation to another system like a 2d renderer or something.
My intention is to have a selectable tank-like underwater vehicle(3 thrusters for movement with rotatable turret)
Originally I had:
Chassis <-- Turret
And then changed it to:
Tank <-- Chassis <–Turret
(Arrows indicate child-to-parent relationship)
The tank node is just a basic dynamic node. The Chassis and Turret both have Rigid Body Controls and belong to separate groups(2 and 3) so as not to collide with each other, and a hinge joint between them. However, so tanks would collide with each other properly, I added the node “Tank” to each tank which i applied a collision box(group 1). I also apply the selection box to the Tank node so as to encapsulate all children with “getWorldBound”. However, since the thrusters are applying forces to the Chassis, the Chassis will move and leave its parent node “Tank” behind with its selection box.
I admit, my gut feeling is that this is not the proper way to do it, I just cannot think of a better way right now.
How might I better use the API instead of trying to change its behavior?
First understand how the API works, then implement your code to do what you want, then connect the two This is one of the most important (and actually fun) parts of programming, thinking about how you implement the application using the features of the language, API etc. I mean in the end you want a game and not code, right? And don’t worry too much about doing things “wrong”, even advanced programmers rewrite complete parts of their application because the implementation changes over time. No line of code you write is ever wasted, you learn a lot by simply doing (even wrong things)