I’m still alive – my wife and I are both working essentially full time at the moment, and I’m discovering that in between work and getting things done at home there’s not a whole lot of time left over for much of anything else. It’s a far cry from my bachelor days of just driving past the nearest drive-thru.
I get around six-to-twelve hours a week to do whatever I like. A good chunk of that goes to programming. In the process of working on the AI, I uncovered the problem: I do not have a ‘scene hierarchy’. Since I’ve been working with actors that essentially consist of one ‘part’, this hasn’t been an issue. Now that I have actors that want to interact with each other, and in particular, respond to the position of other actors, I need to properly put these items into an object hierarchy.
My actors can have a rigidbody component. A rigidbody component can specify one other rigidbody as it’s parent. There can be a chain of rigidbody’s, or a tree-like structure.
At the root of the tree is the galactic centre, x/y/z all equal zero. I have an empty rigidbody (no actor) assigned as the root. When I create a new actor (and it’s associated rigidbody), I can specify that the root is it’s parent. This means that the actor rotates and translates around the root, more commonly known as ‘world space’.
So far so good.
I should then be able to create a new actor (and rigidbody) and assign that previous actor as this actors parent. That means, when the first actor moves, this new actor should follow it along, as if the parent is it’s new centre of the universe.
That’s what I’m working on at the moment. The immediate value is that I’ll be able to include multi-object actors that can animate independently of each other (e.g. the wheels on a car). In the long term, an object hierarchy also allows for critical optimisation – when I walk the tree to work out what objects need to be updated, I only need to perform movement calculations once-per-parent, and all it’s children can inherit their parent’s offset. Better yet, that parent can itself inherit it’s own parent’s offset, and so on up the tree, until it can be rationalised back to world-space.