Debug not working :/

I can’t debug certain properties and I get some deprecation errors.
Please help me if you can and direct me to a relevant python site :smiley:

Thanks in advance.

Ok, now I totally messed up my file. If you know how to make a property on an object represent degrees please show me :confused:


Ok, I dug some more into it and was able to alter the code so that there are no deprecation warnings.

cont = GameLogic.getCurrentController()
own = cont.owner

X = 0
Y = 0
Z = 0

print own.localOrientation [0]

What I now get is [1.0, 0.0, 0.0]

My question is how can I translate the localOrientation into degrees and update the object properties X,Y,Z. :X

Sometimes its easier to align the object to a vector or use a drot actuator. What exactly are you trying to do that you need the orientation matrix?

The reason I need the angle is because I need to calculate how far it is to the point where the eye is looking.
I know I can use rays but in later versions this will not suffice.

Thanks in advance :smiley:

I’m not sure I understand what you’re saying.
If you need degrees you can use something like this:

import Mathutils

ob = ...
ori = ob.orientation

mat = Mathutils.Matrix(ori[0],ori[1],ori[2])
rot = mat.toEuler()

xrot = rot[0]
yrot = rot[1]
zrot = rot[2] # in degrees from memory, otherwise use math.degrees(rot[0])

For more information on the Mathutils module visit the BGE docs and navigate to Mathutils (top left box)

cont = GameLogic.getCurrentController()
own = cont.owner

import Mathutils
import GameLogic

scene = GameLogic.getCurrentScene()

ob = scene.objects[“OBCube”]
ori = ob.orientation

mat = Mathutils.Matrix(ori[0],ori[1],ori[2])
rot = mat.toEuler()

own.ORI_X = rot[0]
own.ORI_Y = rot[1]
own.ORI_Z = rot[2]

Wohoo XD Successful script :smiley:

Thanks mate, much appreciated :smiley: By the way, if something in the script is inefficient or should be done another way please give me a hint, don’t tell me right away.

I’ll post updates in a few days to show you what I’m trying to do.

mkay, I’ve been trying for a few days now and I just don’t know how.

I’m trying to make it so that on every other frame, the Z rot of the camera is what it is +/- 0.2135 degrees.

Help anyone?

Using my last script and the .toMatrix() function:

import Mathutils

ob = ...
ori = ob.orientation

mat = Mathutils.Matrix(ori[0],ori[1],ori[2])
rot = mat.toEuler()

rot[2] += 0.2135 # add 0.2135 degrees

mat = rot.toMatrix() # convert the euler rotation back to a matrix

ob.orientation = [mat[0], mat[1], mat[2]] # apply the new matrix

Its possible.

Btw, why are you using 0.2135 degrees? If you are going to be constantly rotating something its probably better to use angular velocity.

Depending on the focus of the camera, it will rotate from left to right every other frame. The point is to get a 3d effect without the use of any extra things, no goggles no special screens or programs, just blender and your eyes :stuck_out_tongue:
Aight, now back to hacking that file together :stuck_out_tongue: I’ll post a demo tonight if I don’t completely screw up again XD

PS: Almost forgot, thanks mate :wink:

i have a similar problem if i have a prop on a gun thats laying on the ground it wont work with the gun in char hand

Is there a “set active camera function” ?. I searched and looked at the bge/py-document and found the set and use viewport commands but I don’t know how to use them.

hi John_tgh,

To set the active camera, you have 2 options.

  1. You can use logic bricks – Scene Actuator >> SetCamera

  2. You can use python – active_Camera variable in Class KX_Scene