- Home /
transform.rotation not correctly rotating object
Hello. I'm currently experiencing an issue with the transform.rotation command. When I attempt to transform my object using this command, which points my object using the right stick on an XBOX 360 controller --
transform.rotation = Quaternion(0,(Mathf.Atan2(Input.GetAxis("FIRE X"),Input.GetAxis("FIRE Y")) * Mathf.Rad2Deg )+90,0,0);
it fails to actually execute the rotation correctly. What actually occurs here is that the object will always correctly point up and down at 0 and 180 degrees, but in anything other than the two the object fails to rotate at all, simply hold rotation at 0 or 180 degrees. Is there another way this command can be parsed in which will give the desired effect?
Thanks in advance.
your thinking way too hard. Ins$$anonymous$$d of "FIRE X" try "Horizontal" it's a correctly, pre-defined object used for this stuff. Also "Vertical"
@maroonrs2: "Horizontal" and "Vertical" are not objects ;) They are virtual axis which are defined in the Input$$anonymous$$anager. We don't know to what buttons / axis "FIRE Y" and "FIRE X" are bound to, so i guess he knows what he's doing ;)
Those axes are already being used for vertical and horizontal $$anonymous$$OVE$$anonymous$$ENT, not firing. This script is to be used in a twinstick shooter, therefore I had to create two new axes and also configure them a certain way to perform such. I wasn't aware this site's objective was to obliviously criticize projects and code snippets.
Answer by Bunny83 · May 06, 2012 at 08:24 PM
Sure, you set the components of the quaternion manually! The components shouldn't be accessed manually since they doesn't represent angles. Use Quaternion.Euler() to create a rotation of the given euler angles.
For more information see Quaternion
Oh, PEB$$anonymous$$AC error. Why didn't I think about that before? Thanks.
;) a lot people got fooled by this. In other engines that also uses quaternions they usually provide a constructor that takes eulerangles, so it's easy to mix up the two things ;).
Usually no one want's to create a quaternion manually :D