- Home /
Quaternion partial offset, need help badly
I previously had a question about a quaternion offset that was answered here: http://answers.unity3d.com/questions/289184/gyro-quaternion-offset.html. So I have a initial position that I want to rotate to, and I rotate to it with a tween. I'm currently adjusting my iPad screen to look where the gyro is looking around a 3d scene, so after it rotates to this initial location I use the fix found in the link above: in Start() I do
initialRotation = transform.rotation; gyroInitialRotation = Input.gyro.attitude;
and in Update():
Quaternioun offsetRotation = Quaternion.Inverse(gyroInitialRotation) * Input.gyro.attitude; transform.rotation = initialRotation * offsetRotation;
This works great, except I'm finding that a lot of users tip the iPad down when they're looking at this app. So what happens is that when it is tilted like that they are looking perfectly out the window, but then they readjust and they hold it straight and look to the side. This causes the door to be at an angle since it thinks that looking perfectly straight was at this slight tilt.
So I want to offset to the initial rotation of a predetermined rotation, but not in a certain axis. Specially, they are rotated into the car with the iPad titled, all of the rotation is offset correctly except for tilt away/towards rotation. So if they are slightly titled they will be looking at the dash, or the radio, or whatever degree of tilt they're currently using, but they're facing the right direction. That way when they hold it straight up and down and look around, nothing will be on an angle. If anyone has any suggestions or help, I'd greatly, greatly appreciate it.
Thanks.
Or is there another solution to the problem that someone sees?
So this is quite hard to get your head around :) Are you saying you want the rotation around the X axis to be ignored in the initialization phase? Or always?
I would like it so that ins$$anonymous$$d of offsetting perfectly to the point that I have defined (the looking out the windshield one) that it ins$$anonymous$$d looks in the direction of the windshield (so all but 1 of the axis) and ignores the tilt down. From there I'd want to be able to look around the scene using the gyro as I can now. with the above code.
And is that represented by the X axis tilt of the device (it feels to me like that is the one that is looking up or down)? If so can you not just get the Quaternion, use the euler angles and reset that (gimbal lock might be a problem I guess).