- Home /
Find the Y rotation of a cylinderTarget tracked with Vuforia
I've setup the CylinderTarget AR tracking sample from the Vuforia website and it's tracking a Coke can well.
I'm trying to use the rotation of of the tracked can to control other aspects of my game.
When the can is pointing up, reading the rotation around the Y axis gives the expected result. however reading the y rotation once the cylinder is rotated into other directions by the tracking system messes everything up.
I've tried reading from a few different rotation values, eulerAngles.y, localEulerAngles.y, localRotation.y and just rotation.y but none seem to give me just the rotation around the local y axis.
When I spin the physical can on its Y axis, the other rotation values (Z and X) always change wildly too.
I know this could seem to be more of a Vuforia topic than Unity but I think I'm just missing something fundamental about Unity rotation transforms.
what I'm I getting wrong?? thanks.
I
(I've set the ARCamera to World Centre Mode to CAMERA so that the Cylinder is the thing that moves not the camera.)
Not a lot of experience with Vuforia, but Vuiforia rotates the camera, not objects, so your object is not rotating unless you are writing code that explicitly rotates it.
I found a setting in Vuforia to rotate the object ins$$anonymous$$d. - it's the World Centre $$anonymous$$ode setting I mentioned above.
Answer by robertbu · Oct 02, 2014 at 04:19 PM
I'm assuming you are reading transform.eulerAngles.y to get your rotation. The problem with eulerAngles is that they change representation. For example if you set a rotation of (180,0,0) and immediately read it back, you will get a rotation of (0,180,180)...the same physical rotation represented differently. I don't know how you are using this information. For some uses, the problem can be solved using vectors. Here is one calculation that may give you what you are looking for for some uses:
var heading = Mathf.Atan2(transform.forward.z, transform.forward.x) * Mathf.Rad2Deg;
Note that the reference is the ground plane, and this calculation will fail if the local 'y' axis is parallel to the XZ plane.
Hi robertbu!. I'm trying to achieve something related to this. What I want is to detect the real world tilt/yaw/rotation along z-axis of a cylinder target in degrees independent of device camera rotation. I know this might need a slight modification in the equation you posted above, but i am not sure cause I don't understand the math behind Atan2. Will this calculate me the realworld z rotation of the detected cylinder target:?
var yaw= $$anonymous$$athf.Atan2(transform.forward.y, transform.forward.z) * $$anonymous$$athf.Rad2Deg;
Your answer
![](https://koobas.hobune.stream/wayback/20220613164240im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
how to rotate GameObject towards joystick 1 Answer
transform.Rotate will not work 1 Answer
Multiple Cars not working 1 Answer
Moving Camera on player stop then move and rotate to separate point? 0 Answers