How do I get a point (3-tuple [x,y,z]) that is ‘in-front’ of the object? Say I want to get a point that is a gameobjects.xyz + 20 units along the gameobjects local y-axis.
I think I might have to a vector to get this, but I just can’t figure out how to put a Vector and a 3-tuple together to get a position along an objects local axis. I was going
to use a second object, align it to the first objects position and orientation, then move the second object along it’s local y-axis, then use the second object to get the position. but this was going to get messy quickly as I am needing to get quick a few positions that are offset from an object.
I hope this makes sense, I’m finding it difficult to describe my problem, but hopefully I got enough in there
Let’s say your object is at position [x,y,z] and you want a point three units in front of this (+y-axis).
If we simply add [0,3,0] to [x,y,z] the point will always be three units towards the world +y-axis. This only works if the game object is always pointing towards the world +y-axis. What if our object is pointing towards the +x-axis? Or the +z-axis? Or a combination?
This is you’re question right? haha
Anyways, we know now that the point in front of the object on the +y-axis relies on the orientation of the object.
So we can conclude that if we multiply the vector (point in front of object) by the orientation of the object, this must give us the local vector.
Here’s how you would do it in python.
from mathutils import Vector
object.worldPosition + object.worldOrientation*Vector([0,3,0])
Amazing reply Linkxgl. Thank you for explaining that so well.
Its about time I polished up my knowledge of Vectors and Matrices, I keep getting stumped by similar problems, just because of my short knowledge of them. But your solution makes complete sense to me and has helped me understand them a bit.
since 2.62 there is no need to reconstruct the transformation matrix manually.
I do not know why the it is called transform rather then transformation. Regardless of that this attribute comes pretty handy ;).