"Track To" with axis other than Z as up?

Hello again,

So, in my little 2.5D game I want to have a “turret” track to the player whilst remaining flat on the Z-X plane (rotating on the Y axis only, hence, 2.5D game). I can set up the logic bricks/python such that it does indeed track to the player, but getting it to stay axis locked to Y is another matter. With pretty much any setting, it tumbles when the player is directly above and below, or otherwise does not remain flat.

The problem appears to be caused by Track To being hard-coded to lock an axis to Z; that is, you can choose which object’s axis is aligning, but what it is being aligned to is always Z.

I can’t figure a way to make it work, aside from trying something really hacky, like using Math™ to get the vector between enemy-player, then alignAxisToVect using said vector. Or (maybe) using bge.constraints.setGravity(x, y, z) to change gravity’s direction.

(Note that I am, in fact, already using alignAxisToVect to align the turrets up/down to Y (Thank you Nines <3) so that alone unfortunately doesn’t appear to be able to solve the issue.)


Is there not a setting in the actuator to set an ‘up’ axis?

“using Math™ to get the vector between enemy-player, then alignAxisToVect using said vector.”
is not a bad idea at all. The track-to actuator is known to be Wonky.

If you want to get more advanced, and if your turret fires projectiles (rather than ray-cast bullets), have the turret factor in projectile speed and player/target velocity into its vector to lead its shots.

I did something like that for my “IVA” project. The code should still be in that blend somewhere. I may have to do some digging.

Hello hello,

Is there not a setting in the actuator to set an ‘up’ axis?

There is that setting, yes. It’s the drop-down list labeled “Up Axis” in your picture.

Unfortunately the purpose of that entry is apparently for setting which Object axis you want to be pointing up, it does not set which global axis up actually is; it is always +Z. That is to say, “up” is always defined as the global axis +Z, which you can align one of the objects 6 axis to.

Think about this…

With alignAxisToVect you need two vectors.
(1) The object vector you are aligning.
(2) The global vector you are aligning to.

For TrackTo to function though, you need THREE vectors…
(1) You need to know the object’s top, or he may be upside down. (drop-down list)
(2) You need to know where your face is, so you can point it at the enemy. (Track Axis)
(3) You need to know the worlds up, to point the head at. (No setting for this ???)

The problem arises because you can only adjust two of these things. The one you can’t adjust, world up, is hard coded to always be +Z. This means that for any locked TrackTo rotation will always be on Z… but I need it to be on Y.

If you want to get more advanced, and if your turret fires projectiles (rather than ray-cast bullets), have the turret factor in projectile speed and player/target velocity into its vector to lead its shots.

Was planning on lasers, but I will keep this in mind when I get more adventurous. I can definitely see something like missiles that move more slowly having(needing) some kind of target leading. Though I have to admit, somethign like this may be beyond me.

I did something like that for my “IVA” project. The code should still be in that blend somewhere. I may have to do some digging.

If you could do that, it would be fantastic. Thanks.