Python loop

I need a small bit o python that I am having some trouble wrapping my head around

I need a key-press (numpad 2) to change the limits on a axis of rotation,(angle Y)
of a 6dof script, marcoIT made something like this a while back, but I don’t remember what is was called or what thread it was on

Angle limit Y on 6dof joint of current
from (-12.5 -> +12.5)
To ( -12.5->+25 )

this is for high stepping for stairs etc, but I am not sure how to do it, as there is still no 6dof Logic node >:| and the code for the 6dof is harder to find then some other sections…

constraint_type = 12 #6DoF joint
flag = 128 #No collision with joined object.joint = bge.constraints.createConstraint(object_id, target_id, constraint_type, piv_x, piv_y, piv_z, piv_Rx, piv_Ry, piv_Rz, flag)joint.setParam(0, float( settings.get(“x_min”, 0.0) ), float( settings.get(“x_max”, 0.0) ) )joint.setParam(1, float( settings.get(“y_min”, 0.0) ), float( settings.get(“y_max”, 0.0) ) )joint.setParam(2, float( settings.get(“z_min”, 0.0) ), float( settings.get(“z_max”, 0.0) ) )#Parameters 3 = limit x rotation, 4 = limit y rotation, 5 = limit z rotationif settings.get(“Rx_min”, None): joint.setParam(3, float( settings.get(“Rx_min”, 0.0) ), float( settings.get(“Rx_max”, 0.0) ) )if settings.get(“Ry_min”, None): joint.setParam(4, float( settings.get(“Ry_min”, 0.0) ), float( settings.get(“Ry_max”, 0.0) ) )if settings.get(“Rz_min”, None): joint.setParam(5, float( settings.get(“Rz_min”, 0.0) ), float( settings.get(“Rz_max”, 0.0) ) )

this is what I need to manipulate

Hi ,

you have to grab the id of the constraint created ,
it should be in a property of the obj

and then change it with : setParams(val1,val2,val3)

i dubt that can help ,but is too complex, youi need to know python before , no way… :wink:

this is a very good reference : except some syntax changes (OBCube now is -> Cube)

Can you take a look at the .blend I sent you?

the code is for the “hips”

so holding (numpad2) will change the Y axis constraint from (-12.5 through 12.5 ) to (-12.5-25.5) ?

I plan on donating the whole rig with a skeleton, and a Quadruped rig after I finish it, but I need to get through this,
If you could write the code (I don’t know why but as soon as I get codelonger then a page my brain goes all retarted)
I have dyslexia, and can code python in snipets… but to much on one page… and my eye’s can’t focus, and I am not sure why, but I can’t seem to focus today,

in the rig , wsad -head motion
Alt, start walk cycle
Q-E turn left/right while walk cycle is active

################# 6DOF Rotational Motor Constraint

import PhysicConstraints Module

import PhysicsConstraints

get current scene

scene = GameLogic.getCurrentScene()

get object list

objList = scene.objects

get object named OBCube_Green

obj1 = cont.owner

get object named OBCube_Red

obj2 = objList[“Center”]

want to use a 6DOF constraint

constraintType = 12

get obj1 physics ID

obj1_ID = obj1.getPhysicsId()

get obj2 physics ID

obj2_ID = obj2.getPhysicsId()

Use center of obj1 for pivot point

pivotPos_X = 0.0
pivotPos_Y = 0.0
pivotPos_Z = 0.0

Make pivot axis orientation same as obj1 axis

pivotAxis_X = 0.0
pivotAxis_Y = 0.0
pivotAxis_Z = 0.0

disable collisions between obj1 & obj2

flag = 128

create a 6DOF constraint

cube_6DOF = PhysicsConstraints.createConstraint( obj1_ID, obj2_ID,
pivotPos_X, pivotPos_Y, pivotPos_Z,
pivotAxis_X, pivotAxis_Y, pivotAxis_Z,

set rotation around pivot x and y axis to zero

cube_6DOF.setParam(3, 0.0, 0.0)
cube_6DOF.setParam(4, 0.0, 0.0)

create rotational motor around the pivot z axis

cube_6DOF.setParam(11, 1.0, 100)

is what I have so far, but don’t know how to convert a X,Y,Z - to a rotation matrix
or is
cube_6DOF.setParam(3, 0.0, 0.0)-X axis?
cube_6DOF.setParam(4, 0.0, 0.0)-Y axis
cube_6DOF.setParam(5, 0.0, 0.0) -Z???

get current scene

scene = GameLogic.getCurrentScene()

is generating errors, what is the current syntax?

I am pretty sure I can just edit
cube_6DOF.setParam(3, 0.0, 0.0)-X axis?
cube_6DOF.setParam(4, 0.0, 0.0)-Y axis
cube_6DOF.setParam(5, 0.0, 0.0)
this bit, and delete the motor part,

So .43633231299858 radians= 25 degrees?

On this, the Python API uses the radian measurement for angle instead of degrees.

Radians are based on pi (3.14). If you printed out the radian value while an object is rotating, you’d go from 0 - 3.14 and then 0 - -3.14. (might be the other way though, don’t remember).

Also, if you need to manipulate matrices directly, skip trying to do it manually and read up on the mathutils library instead, there you will learn that you can convert a matrix to a set of easier to use Euler values and visa versa. (in other words, you can create matrices and set the orientation to use that matrix).

get current scene

scene = GameLogic.getCurrentScene()

is generating errors, what is the current syntax???


You know, if you’re having a lot of trouble with lines this simple, you really should work to brush up on your Python skills on your own through reading the manual, reading tutorials, and downloading examples. The syntax for one thing has had some changes since 2.4x and the manual should have all of the latest functions and module names.

now that I know that it changed, and when, I can deal with it…

I am learning as I go :slight_smile:
it worked btw, thank you :slight_smile:

turns out I was using linear servo motions though for the feet when I should have been using Angular or torque on the hip and force+torque on the knee :slight_smile: