Gameblender Python Question (matrix math)

Ok i have this dandy script that someone else wrote. It works for the most part but for what im using it for it fails. ( I have modified it for my needs)

All im wanting is a ant(object) to follow around another object , like a cylinder and just keep walking around it.

so far it works however when it gets to the bottom the orientaion is messed up so it turns it around and bad things happen.

What i need is how to exclude a axis or more when its setting orientation.
I don’t know how to acces that data though.

from math import sin, cos, sqrt
#---- reprsent tab for the sake of forum integraty

vector functions!!

def VEC_length(x):
------- return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])

def VEC_normalize(x):
------- length = VEC_length(x)
------- return [x[0]/length,x[1]/length,x[2]/length]

def VEC_cross(x, y):
------- return [x[1]*y[2] - x[2]*y[1],
--------------------- x[2]*y[0] - x[0]*y[2],
--------------------- x[0]*y[1] - x[1]*y[0]]

def VEC_min(x, y):
------- return [x[0] - y[0], x[1] - y[1], x[2] - y[2]]

def MAT_trackvector(fw, y):
------- if abs(abs(fw[2]) - abs(y[2])) < .001: #prevent gimbol lock
------- ------- y.append(y[0])
------- ------- del y[0]
------- right = VEC_normalize(VEC_cross(y, fw))
------- up = VEC_cross(fw, right)
------- return [[right[0], up[0], fw[0]],
-------------- [right[1], up[1], fw[1]],
------- ------- [right[2], up[2], fw[2]]]

cont = GameLogic.getCurrentController()
obj = cont.getOwner()
ray = cont.getSensor(“ray”)
if obj.time == 1: #used to offset the ray so its not constant.
------- if ray.isPositive():
------- ------- hit_pos = ray.getHitPosition()
------- ------- hit_norm = ray.getHitNormal()
--------------*** #What i need is a way to seperate the matrix here and just follow one of the axis
-------------- obj.setOrientation(MAT_trackvector(hit_norm, [0.0,0.0,1.0]))
-------------- pass
-------------- obj.setPosition(hit_norm)
--------------***#Same with here I need only change one of the axis positions so i can adjust how far or close it is to the object ray is looking at.
-------------- obj.time = -5

Could someone expliain some of hte matrix math to me or help me figure out the 2 *** questions above


 block for python [the spaces will be preserved], not a [quote] block

so you want an ant to track it's left vector to a point, and continue walking forward?

Thx for the code tip. Here is the blend I was working with. The reason im asking as you will see, when the ant gets to the botton its z rotation gets reversed and messes things up, If I can just control its x or y then it will continue to follow around the sphere

I will work on code futher after i get this fix so he can follow as if he was in the circle instead of outside of it. (will need some more planing)

To exclude an axis, either ignore it or set it to a constant value.

To walk in a circle you need the radius and the starting angle. You have radius (i.e., length). The angle is invtan (y/x) or invsin(y/length) or invcos(x/length), whichever you want to use.

After you have this information, the next x and y are found by increasing the angle and calculating

x_new = length * cos(angle_new)
y_new = length * sin(angle_new)

Set this up in an iterative loop. It should repeat every 360 degrees.

Im sorry but that is not what I need.

The Ideal is to have it follow the direction of the normals no matter what angle. If you would of downloaded my demo you would of see my concern.

I do not know how to access just one part of a matrix.

like the getOrientation command. (how do i seperate the differnt axis so that i may only pass 1 or more axis to the object (setOrientatoin))

If i wanted it to move in a circle I simply would of attached it to a empty at the center and did a rotate.

Thx for trying.