I am trying to do a clone of the old Elite game, and I’m having a lot of trouble getting the ship to move in the right way.
For those of you who aren’t familiar with Elite, it’s a space game where the ship moves at a constant velocity forwards, and the user can control pitch and roll.
It seems like pitch is always in terms of a global up-down, so when I roll the ship sideways 90-degrees, then “pitch up” this pitch up is always in the global up direction, and not towards the ship’s “up”. I want a roll 90 degrees to the right, then a pitch up to amount to yaw right.
I’ve tried making a series of nodes and applying position change to one node, pitch to another node, and roll to a third node. But this doesn’t quite seem to work out. Either pitch continues to be tied to the global “up-down”, or roll is always around the original forward vector.
What is the right way to do something like this?
Did you try to do it this way:
np.setP( np, deltaPitch )
np.setP( np.getP( ) + deltaPitch )
If not otherwise specified a transform (x, y, z, heading, pitch, roll) is always in the coordinate system of the nodepath’s parent. To get a transform relative to the nodepath itself and not it’s parent you have to pass the nodepath as the first argument before the transform. To get a global transform you have to pass the top nodepath a the first argument, which is usually “render”, or use “np.getTop( )” to find it explicitly.
If you get this working PLEASE let me know. I loved that game. I use to play it for hours on my C=64. I liked it becasue of the planetary resouces and trading systems. It just was not a straight shoot’em up.
Let’s say you want to pitch the ship slightly to the right. Do this:
oldtransform = spaceship.getTransform()
deltatransform = TransformState.makeHpr(0,5,0)
newtransform = oldtransform.compose(deltatransform)
So I get the old orientation of the spaceship, then “compose” that with a slight pitch to the right. When you “compose” two transforms, you’re making the second transform relative to the first. Ie, you’re adding a slight pitch to the right relative to the current orientation of the spaceship.
Small warning: I sometimes get the “compose” order confused. Maybe it’s supposed to be deltatransform.compose(oldtransform)? I always get all dyslexic with this.
Here’s another fun way:
deltaorientation = Quat()
What you need to know is that a quaternion is a nice way to store orientations. The ‘multiply’ operator on quaternions does the same thing as the ‘compose’ operator on transforms - it makes the second one relative to the first one. So I’m composing a relative pitch to the right to the existing orientation.
Panda will do all these operations for you with one call:
spaceship.setHpr(spaceship, 0, 5, 0)
This means to pitch the spaceship 5 degrees relative to the spaceship–that is, rotate the spaceship 5 degrees from its current position.
Go figure. I should have known it would be easier.