ok here is my file
http://www.pasteall.org/blend/25355
it’s a little big due to models+textures etc.
So, I am using rays to get hit normal to apply gravity,
I also need to get the alignment of the face and pass it using
Center[‘Zaxis’] = Vector
To another script to balance more then 1 limb with the new Z axis
Right now, the Z gravity works, but I have something wrong in the script text.004 (great name huh?):spin:
import bge
from mathutils import Vector
from bge import render
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
Center=scene.objects['Center']
sen = cont.sensors['Ray']
hitNormal = sen.hitNormal
if hitNormal: # check before if the ray hit something
render.drawLine(sen.hitPosition,own.worldPosition,(255,0,0))
hitNormal = Vector(hitNormal) # transform in to Vector
axisZ = own.localOrientation.col[2]
v1 = axisZ
v2 = hitNormal
rotDif = Vector(v1.rotation_difference(v2).to_euler())
Center['ZaxisX']=(Center['ZaxisX']+axisZ.x)/2 #wrong?
Center['ZaxisY']=(Center['ZaxisY']+axisZ.y)/2 #wrong?
Center['ZaxisZ']=(Center['ZaxisZ']+axisZ.z)/2 #wrong?
rot = own.worldAngularVelocity
rot += rotDif *.5 #"elasticity"
rot *= 0 # inertia
own.applyForce(-hitNormal*9.8*own.mass*6)#gravity to the normal
So, Can someone take a look at it,
I want the player to run on the surface, regardless of it’s orientation.
here is the balance code that uses the Center[‘Zaxis’]
GamelogicSimple.py
import bge
cont = bge.logic.getCurrentController()
from mathutils import Vector
own = cont.owner
scene = bge.logic.getCurrentScene()
Center=scene.objects['Center']
head = scene.objects['HEad']
axisZ = own.worldPosition.copy()
axisZ.x= Center['ZaxisX']
axisZ.y= Center['ZaxisY']
axisZ.z= Center['ZaxisZ']
quat = axisZ.rotation_difference(Vector((0,0,1)))
vec = Vector(quat.to_euler())
vecmag = vec.magnitude
torque = own['Force']*1
own.applyTorque(torque*vec*vecmag,0)
head.applyForce(-10*vec,0)