Align axis to vector

How would you align axis to a vector of another object or could you tell me what page it is on?I was looking at blender 2.62 api and trying things.

import bge

def alignToSphere(cont):
    scene = bge.logic.getCurrentScene()

    own = cont.owner
    sphere = scene.objects['Sphere']

    vector = own.getVectTo(sphere)[1] #Y_Vector
    own.alignAxisToVect(vector, 2, 1) #vector = vector to align to, 2 = axis number to align, 1 = speed to align, between 0 and 1
    

vecY = other.worldOrientation[1] #1 is the Y

own.alignAxisToVect(vecY, 1, 1) #vectReference, vetorToAlign, speedToAlign(0=min,1=max)

EDIT: ops … too slow :wink:

That is not the complete code agoose although it looks like it.What is it missing a property?

It is the full code, you use it in module mode, and change the name of the object you wish to align to

What do i put in the module mode though for it to work?

Make a text file: align.py
Always True Pulse -> Python Module (align.alignToSphere)

This is the error i got when i did that.



Blender Game Engine Started

 
Python module can't be imported - object 'Cube.004', controller 
'Python1':

 
ImportError: No module named align

 
Blender Game Engine Finished

the text file needs to be called align.py in the blender text window.

Mine does give me a picture of your logic bricks for it.

try this ,

this work ever with a always sensor true, but with a script (no module) which is more easy to use.


import bge

own     = bge.logic.getCurrentController().owner
scene   = bge.logic.getCurrentScene()
sphere  = scene.objects['Sphere']

vector  = own.getVectTo(sphere)[1] #Y_Vector
own.alignAxisToVect(vector, 2, 1) #vector = vector to align to, 2 = axis number to align, 1 = speed to align, between 0 and 1

or this,which is a bit different (but again without module)


import bge

own     = bge.logic.getCurrentController().owner
scene   = bge.logic.getCurrentScene()
sphere  = scene.objects['Sphere']

vector  = sphere.worldOrientation[1]
own.alignAxisToVect(vector, 1, 1)

I think i didnt capitalize the word sphere that is why it didn’t work.

It behaves like a track to actuator or is that its purpose?

That is what you asked for.