# Constrain Local Orientation?

Is it possible to constrain the local orientation of an object inside the GE?

The orientation constraint only seems to work on the global axis. My set up uses a modified version of the MouseLook.py from www.tutorialsforblender3D.com. I am using this script on the camera with just the up/down actuator. I want to keep the camera from being able to flip completly over 360 degrees (it’s an fps).

I’ve been trying some stuff in python but I cannot seem to find anything that will work in the GE. I know it’s possible(I have seen it done) but, I’m not python savvy enough to understand how at the moment.

-Wynn

I looked at the code for MouseLook.py, and I noticed the way he’s getting his axis vectors:

``````
# get the orientation of the camera to world axis
camOrient = obj.orientation

# get camera Z axis vector
camZ = camOrient[2]

# create camera z axis vector
vec1 = Mathutils.Vector(camZ)

# get camera parent
camParent = obj.parent

# get parent orientation to world axis
parentOrient = camParent.orientation

# get parent z axis vector
parentZ = parentOrient[2]

# create parent z axis vector
vec2 = Mathutils.Vector(parentZ)

``````

But that doesn’t seem right, because (and I’ve ran tests to prove this…to myself) the axis vector is represented by the columns of the orientation matrix, not the rows.

So, “camZ = camOrient[2]” doesn’t really give you the Z axis vector, it just gives you the z components of all vectors.

The code that retrieves the Z axis vector from an orientation matrix should look like this:

``````
CamZ = []
for i in range(3):
CamZ.append(camOrient[i][2])

``````

The same technique should be used to get the parent Z axis vector, as well.

If you do that, the “cap” should work “locally”.

hi C. Wynn,

The orientation constraint in the Constraint actuator is global. As far as I know, there isn’t any way to make it local.

MouseLook.py: Capping of the Camera is local and not global. The Camera Z-axis is capped to the Z-axis of the Camera’s parent.

Because you’re using a modified version of MouseLook.py, without a blend it’s hard to say what needs to be done to fix it. If you want me to take a look at it but don’t want to post the blend here, you can e-mail it to me at my website, tutorialsforblender3d.

Also, there are some other Mouselook scripts that you might find easier to modify. I’ve probably forgotten some but these 3 work really well.

Clark

Did you read my previous post?

I think that should do the trick in this case.

Give it a try.

hi Social,

The orientation constraint in the Constraint actuator is global.
The Constraint Actuator Logic Brick. As far as I know, there isn’t a python method/variable that changes the Orientation Constraint from global to local.

Clark

The mouseCap function in MouseLook.py can be modified (in the manner described) to actually retrieve axis vectors correctly, and that alone should make the cap local.

You could extend the very same concept to some general “rotation cap” scenario.

Hmmm,

This doesn’t look like the code that I’m using.

Here is the code. I took it out of a blend that had a sample skybox in it. It’s a lot simpler; I don’t remember where I got it really:spin:. It was posted here and I assumed that it came from “tutorialsforblender3D”.

Basically all I did to modify it was to remove all the “left/right” pieces which I’m not using.

``````######################################################
#
#    MouseLook.py        Blender 2.46
#
#    Tutorial for using MouseLook.py can be found at
#
#    www.tutorialsforblender3D.com
#
######################################################

# import Rasterizer
import Rasterizer

# get controller
controller = GameLogic.getCurrentController()

# get the object this script is attached to
player = controller.owner

# Get sensor named Mouse
mouse = controller.sensors["Mouse"]

# Get the actuators
lookUpDown = controller.actuators["LookUpDown"]

# get width and height of game window
width = Rasterizer.getWindowWidth()
height = Rasterizer.getWindowHeight()

# define mouse movement function
def mouseMove():

# distance moved from screen center
x = width/2 - mouse.position[0]
y = height/2 - mouse.position[1]
# intialize mouse so it doesn't jerk first time
if hasattr (player, 'mouseInit') == False:
x = 0
y = 0
# can't use True.  Have to use 1
player['mouseInit'] = 1

# return mouse movement
return (x, y)

# get mouse movement from function
move = mouseMove()

# set mouse sensitivity
sensitivity = 0.0009

# Amount, direction and sensitivity
upDown = move[1] * sensitivity

# Smooth movement
player['oldUpDown'] = (player['oldUpDown']*0.5 + upDown*0.5)

upDown = player['oldUpDown']

# set the values
lookUpDown.setDRot( upDown, 0.0, 0.0, True)

# Use them
controller.activate(lookUpDown)

# Center mouse in game window
Rasterizer.setMousePosition(width/2, height/2)
``````

Unfortunately, I don’t know enough about matrices to understand your sample but, I’ll be sure to look into it in the near future.

hi C. Wynn,

That is an old version of MouseLook.py. I’ve updated MouseLook.py since then and the most recent version is for Blender 2.49b.

If you have Blender 2.49b, take a look at the attached blend. I removed the code for Left/Right movement for you.

It has local Capping for Up/Down. The camera z-axis is capped to the camera parent z-axis.

Right now it’s capped at 30 Degrees. 15 up and 15 down. To change the capping amount, look at the Properties attached to the camera. Cap is the one you want to change.

Clark

### Attachments

MouseLook249_Modified.blend (215 KB)

No, it’s not.

As I already explained, you’re not actually getting the Z axis vector of either object, you’re extracting the Z components of all axis vectors.

I’ve attached an example that illustrates the failure of the cap when the parent’s Z axis is not pointing directly up [0,0,1].

Just keep moving the mouse up, and you’ll see the cap fail. In “Scene2”, the modifications I mentioned in my original post are applied, and as a result, the cap remains effective.

### Attachments

MouseLook249_Exposed.blend (301 KB)

Thank you both for your input cthames and Social. I’ll be able to implement these into my game. As for your fix Social, your solution is elegant but, in my particular situation, the camera is parented to an object which rotates along the z axis only (the camera is fixed in an upright position). So I don’t think I’ll have problems there. I’ll definitely keep it on hand for its usefulness though;).

Many thanks,

-Wynn