Game Engine Local Rotation - Gimbal Lock

Dear everyone,

Thank you for taking time to look at my post. I have a small question involving how you can rotate an object on it’s local axis in the game engine. Either using quarternions or roll pitch yaw.

import weakref
import serial
import bge
import time

controller = bge.logic.getCurrentController()
owner = controller.owner
owner.localOrientation = [yaw,pitch,roll]

The above is my current code, but with localOrientation I am still experiencing gimbal lock. Theres probably a very easy solution like quarternionOrientations but for the life of me, I have been unable to find it, so any help is greatly appreciated. Thank you!

https://pythonapi.upbge.org/mathutils.html#mathutils.Quaternion

From the doc:

# passing values to Quaternion's directly can be confusing so axis, angle
# is supported for initializing too
quat_b = mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(90.0))

So the quaternion will encode a rotation around an axis, at this point you could do object.getAxisVect((0, 0, 1)) to get the local Z axis for instance, and maybe object.applyRotation(quaternion).

I wouldn’t know for sure.

On the other hand, if you use object.applyRotation((x, y, z), True) it should do a rotation with x, y and z as eulers. Don’t know if it will gimbal lock again.

Thank you for your reply!