I'm creating a game where you use rotational remote(it knows only its rotation) to steer a car. I have a problem with converting Quaternion
(this is the output of the controller) to steering wheel rotation.This is what is the closest to working form all the things that I have tried(transform.localRotation is a rotation of the steering wheel):
void Update() {
transform.localRotation = GvrController.Orientation;
transform.localRotation = new Quaternion(0.0f, 0.0f, transform.localRotation.z, transform.localRotation.w);
}
This obviously isn't a good solution and works not so well. There is a very simple visualization of what I'm trying to do: Default orientation of the controller is facing forward as on the picture.
Basically the whole problem is how to skip all the axis other than the one responsible for rotating(axis 1 on the picture) and apply it to the steering wheel. Do you know how can I do this?
EDIT: Because it's hard to explain the problem without proper visualization i took photos of my controller and drew axis on them.
This is the default orientation of the controller:
And this is how it's held with axis marked on it:
Use Quaternion.Euler and Quaternion.eulerAngles. Note the order for the Euler function is z, x then y, unlike Vector3. EulerAngles returns an angle in degrees (whereas rotation.x returns the quaternion amount for that axis). The Euler function expects an angle so you want something like:
Quaternion rot = GvrController.Orientation;
transform.localRotation = Quaternion.Euler(rot.eulerAngles.z, 0, 0);
Depending on how the axes of your controller are set up you may need to experiment with other orientations if it's not y-up z-forward e.g.
transform.localRotation = Quaternion.Euler(rot.eulerAngles.x, 0, 0);
or
transform.localRotation = Quaternion.Euler(0, 0, rot.eulerAngles.z);
and so on. It should soon become clear which system it uses.
Also, if the steering wheel is not parented to anything use rotation rather than localRotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With