- Home /
Always rotates 0 when setting values
So i want the weapon to rotate to the to the x and y of the rotbot, which is a different object that rotates to point at the second hand (its a vr game but that doesn't matter) and then rotate the z to the rotation of the hand holding the object. Take pavlov for example if you know how that works. heres code that should do that
HeldObject.GetComponent<CanInteractWithThis().RotBot.transform.LookAt(HeldObject.GetComponent<CanInteractWithThis>().HandHold.transform);
HeldObject.transform.rotation = Quaternion.Euler(HeldObject.GetComponent<CanInteractWithThis>().RotBot.transform.rotation.x, HeldObject.GetComponent<CanInteractWithThis>().RotBot.transform.rotation.y, this.transform.rotation.z);
this is stopping my development please help. If you have questions about anything that i didn't specify please ask. Thanks
Answer by JVene · Aug 29, 2018 at 03:38 AM
@SPOTNINJADUD7890, First, before we can get to anything else, we have to fix a problem in the code you have posted. in all cases you refer to transform.rotation, you need to realize that the rotation member is a Quaternion. The x, y and z properties of the Quaternion are not angles. They have no meaning to your code. Search the internet for what a Quaternion is to understand what these values are, but I can assure you that you have absolutely no use for them whatsoever.
What you require are the eulerAngles property from the rotation. As in:
RotBot.transform.rotation.eulerAngles.x
That is the angle, in degrees, of the x axis from the RotBot's rotation. The x you retrieved (and, thus, the y and z) are not related to an angle in the slightest.
In my years of developing i have never known this, its funny where you can go in 10 years and never learn something so simple haha. Anyways, this worked absolutely flawlessly. I'm going to accept this and give you 20 rep. Thanks man.
I appreciate the points. Quaternions have an interesting historical point to your comment. Hardly anyone knew they existed during early years of game development.
I forget the inventors name, a British (maybe Scottish, I don't know) man around the 1850's. It was an inspiration on the subject of linear algebra, solving the gimbal lock issue associated with yaw-pitch-roll in 'standard' use. A quaternion algebra was developed to offer equivalent operations to that of linear algebra, and at the time his colleagues considered it a curiosity worth recognition, but with little practical use because the existing methods worked for the need of the period. The subject was all but forgotten for 100 years.
Except, of course, by certain mathematical historians and PhD's. At some point, I think in the 80's or later, there came some discussion between some programmers and at least some historian on the subject, where the Quaternion was resurrected from it's obscurity, because at this point it solves a current problem uniquely. I have some '3D graphics' books from the 80's that never mention quaternion algebra. $$anonymous$$athematically, the quaternion fashions what might be analogized as a 3D compass like device. A vector points to an orienation, with one parameter completing the set with a 'roll' angle along the axis of the vector.
Your answer
![](https://koobas.hobune.stream/wayback/20220612173704im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Inheritance code acts differently (Quaternion.LookRotation) 0 Answers
Rotating a model with increments 1 Answer
Multiple Cars not working 1 Answer
Object won't rotate correctly 2 Answers
Tilt object x degrees, smoothly 0 Answers