Hi. I wrote some code for aligning a sentry towards the enemy. I am using two elements for the sentry, each parented to an empty, and I am using alignAxisToVect to align those empties to the enemy.
The lower element (yellow) should only rotate on the Z axis, and the upper element (red) should only rotate on the Y axis. I have managed to do so with the lower element by assigning a zero to one of the numbers in the vector, however, the same doesn’t work with the upper element. Also, the upper element has a slight tilt.
Please help.
from bge import logic
scene = logic.getCurrentScene()
cube = scene.objects["Cube"]
pivot_z = scene.objects["PivotZ"]
pivot_x = scene.objects["PivotX"]
def main():
vector_x = list(pivot_x.getVectTo(cube))
pivot_x.alignAxisToVect(vector_x[1], 0, 1.0)
vector_z = list(pivot_z.getVectTo(cube))
vector_z[1][2] = 0
pivot_z.alignAxisToVect(vector_z[1], 0, 1.0)
aiming_tilt.blend (434 KB)