Ok, so lets say Ive got a set up like this. Where my cubes rotation is controlled by the movement of the mouse via this script;
from bge import logic as Gfrom bge import events
sensitivity = 10.0
speed = 0.1
owner = G.getCurrentController() .owner
y = 0.5 - G.mouse.position[1]
if abs(y) > 0.001 : owner.applyRotation([ y, 0, 0], True)
G.mouse.position = (0.5,0.5)
But i dont want the cube to rotate all the way around, lets just say 45 and -45 would be the constraints for now, does anybody know how to go about this? Thanks in advanced
1 add a second object in the same location as the other cube, that we will call “center”
import Mathutils
Diff = own.worldOrientation-center.worldOrientation
Diff = Diff.toEuler
Min=-45
Max=45
if (y > .01) and (y + Diff.y<Max):
owner.applyRotation([ y, 0, 0], True)
if (y < -.01) and (y + Diff.y>Min):
owner.applyRotation([ y, 0, 0], True)
## this may need a little correcting
from bge import logic as G
from bge import events
sensitivity = 10.0
speed = 0.1
owner = G.getCurrentController() .owner
#y = 0.5 - G.mouse.position[1]
#if abs(y) > 0.001 : owner.applyRotation([ y, 0, 0], True)
#G.mouse.position = (0.5,0.5)
mouse_y = 0.5 - G.mouse.position[1]
if abs(mouse_y) > 0.001:
### get the rotation in radians
x, y, z = owner.localOrientation.to_euler()
# add the rotation from the mouse imput
y += mouse_y
### set the limit in radians (45° = 0.8 more or less)
min_ang = -0.8
max_ang = 0.8
### adjust the value if out of limits
if y < min_ang : y = min_ang
elif y > max_ang : y = max_ang
### rewrite the matrix (the real matrix is written automatically , these here just 3 floats)
owner.localOrientation = x, y, z
G.mouse.position = (0.5,0.5)
it use “localOrientation” , is so relative to the matrix of parent if there a parent, otherwise is the equivalent of worldOrientation