Hi,

I’m making a slope system for The Dawsich’s game, but it’s all screwed up, for a reason I don’t know. It gets screwed up at the middle of the way and each time I press W it changes directions. I’m posting the script and the .blend file.

Thanks in advance.

```
from math import sin, cos, sqrt
import GameLogic as g
c=g.getCurrentController()
o=c.getOwner()
# 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]]]
sloperay=c.getSensor("sloperay")
hit_norm=sloperay.getHitNormal()
o.setOrientation(MAT_trackvector(hit_norm, [0.0,0.0,1.0]))
```

### Attachments

slope.blend (135 KB)