How can I...

How can I track an object to specific coordinates?

I don’t want to use an object for tracking.

I tried with alignAxisToVect but my object(Dynamic) has a totally weird behavior (It becomes upside-down or bounces)

In a strait line use the ‘track to’ in the edit object actuator, threw a level with turn it will require some python.

move an empty to those coordinates and then track to the empty. You could be using the wrong axis?

I’ve already tried with the empty method. The problem is that the objects that I want to track the coordinates are added with an addobject actuator. Eventually there is a problem when you add 2 copies of the same object that are trying to track two copies of the same empty…

use python; get the vector to the point, then alignAxisToVect.
You may need to right the object before aligning with alignAxisToVect(2,[0,0,1])

I’ve tried that but still my object turns 45 degrees and remains still…

Are you sure the vector you found is the right one? are you sure you plugged it in right? are you sure you’re aligning the right axis? Because that’s the method I use to track objects, and I assure you, it works quite well.

[edit] usually my code looks something like this


g=GameLogic
c=g.getCurrentController()
o=c.owner

target=g.getCurrentScene().objects['OBobjectnamehere']
vec=o.getVectTo(target)[1]

o.alignAxisToVect([0,0,1],2)
o.alignAxisToVect(vec,1)

make sure you’ve got true pulse enabled, or else it’ll just run once and then stop.

[edit2]
the script I posted assumes you want to align the +Y axis toward the target, and the +Z axis upward. You can change the number after the vector to change the axis (0 is x, 1 is y, 2 is z) and invert the vector for -alignment.

The object that tracks the coordinates is the parent of other objects as long as an armature.

Is there any possibility that this fact affects its behaviour ?

if it’s the parent, no, I don’t think it would have any effect.

I really can’t help you without more information, how about uploading a simple blend outlining the problem? (IE if you have a big scene with a bunch of stuff, get rid of everything but the problematic objects)

I’ll try to replicate the problem and send a simple blend file because my game is already too complicated.

http://rapidshare.com/files/355740095/align_problem.blend

I’ve uploaded a file. Play with A,W,S,D,Q and mouse

The code that controls the alignment is in the python script called enemy

I’ve tried to make it as simple as I could.

Well the previous file was much too complicated.
This one is very simple.
If anyone has some time to spare, I’d appreciated it if he took a look.

Attachments

align_problem1.blend (488 KB)

Um… in the file you uploaded, you plugged a specific vector into the track, regardless of where the node is. The enemy aligned to the vector you plugged in, just as you told it to. The trick is, you have to tell it to align to the vector to the target location, not just a specific vector- if the enemy or the target move at all, the vector will change.

I think you might be confusing vector and position; position is a point in space, that tells you where something is. A vector is sort of like an arrow that points in a direction (and always starts at the center of the object). The vector you defined, 0,-12,-18, means the arrow starts at your enemy’s center. To find where the arrow ends (the place your enemy will track to) take the enemy’s position, move 0 along X, move -12 along Y, and move -18 along Z. Basically, you’ve told your enemy to always point down and to the left.

I’ve attached the corrected blend. Note that I’ve used the getVectTo function; this requires that you have an object for the end position. If you want a position that doesn’t have an object (say, from a list, or the position of a vertex in a path node mesh) you’ll have to make your own method to get your vector. The vector to a position is simply the end position minus the start position. (that means [end X-start X,end Y-start Y, end Z-start Z]- you can set the last one to 0 if you want a 2d track)

Attachments

align_problem1_fixed.blend (488 KB)

Thanks a lot. It works perfect!