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.

Script

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