vector of motion?

I’m not even sure if I’m asking the right question, but what I think I’m looking for is a way to get the vector of a body in motion regardless of actual orientation.

I’m working on a space sim, and I have a ship that thrusts in the direction it’s facing (local -y?), but can yaw and pitch freely using DRot.

In the HUD, I want to have a 3D arrow that points in the direction of movement relative to the local orientation of the ship, which I’m thinking is a matter of comparing the vector of motion with the orientation vector.

I can work out the actual math later (I’m currently taking the crash couse on vector mathematics), but am I on the right track? And is there an elegant way of getting these vectors?

orientation isn’t a vector, it is a matrix [or if you wish to consider it that way, 3 vectors]

obj.getOrientation()

and if I recall, in global coords a vector
obj.getLinearVelocitity()

The vector you need is from getVelocity(). It returns the objects velocity on the X, Y and Z axes. Just normalize it to get the Y vector you need to set the orientation. Using that, somehow, you can get the other vectors, X and Z. Don’t ask me how because I don’t know for sure, but it would involve using arc sines and arc cosines and sines and cosines and stuff.

Thanks for the replies, the linear algebra is turning my brain to slag, but it’s starting to come together now. And trig that I took over 15 years ago is just starting to click! :smiley:

Could someone tell me the difference between getVelocity() and getLinearVelocity()? From playing around with them, they seem to return the same numbers, but I didn’t want to assume they’re the same.

Here’s the documentation…

http://blender.org/documentation/pydoc_gameengine/PyDoc-Gameengine-2.34/KX_GameObject.KX_GameObject-class.html#getLinearVelocity
http://blender.org/documentation/pydoc_gameengine/PyDoc-Gameengine-2.34/KX_ObjectActuator.KX_ObjectActuator-class.html#getLinearVelocity
http://blender.org/documentation/pydoc_gameengine/PyDoc-Gameengine-2.34/KX_SCA_AddObjectActuator.KX_SCA_AddObjectActuator-class.html#getLinearVelocity

With getVelocity(), you can pass coordinates of a point in that object to it and it will return the velocity of that point (combining linear and angular velocities). If you do not pass anything to it, it acts just like getLinearVelocity(), which returns the velocity of the object itself, at its origin, without rotation.

So if you use getVelocity(0, 10, 0) on an object that is rotating but not changing position, you will get something other than [0, 0, 0]. I dunno, I’ve never used it…like that…

getLinearVelocity() is also used with the motion actuator.