Comments and answers for "Trig for setry gun aiming works but always aims a bit above the target"
http://answers.unity.com/questions/630002/trig-for-setry-gun-aiming-works-but-always-aims-a.html
The latest comments and answers for the question "Trig for setry gun aiming works but always aims a bit above the target"Comment by Doodles on Doodles's answer
http://answers.unity.com/comments/630570/view.html
Looks like a little thought overnight and your ideas helped me come up with this solution:
Quaternion q = Quaternion.LookRotation ( this.Target.transform.position - this.BarrelBase.transform.position );
this.XAxis.transform.localRotation = new Quaternion ( -q.x, 0, 0, q.w );
this.YAxis.transform.localRotation = new Quaternion ( 0, 0, q.y, q.w );
It came to me that the only identity between euler and quaternions was 0 and that the swivel points on the gun had local rotations 0 on each axis so I came up with this solution. Although the axes were a little switched up on the YAxis swivel point but after some correction, Debug.DrawRay proved it was ai$$anonymous$$g correctly. So thanks for your help!Sun, 02 Feb 2014 16:44:18 GMTDoodlesComment by Owen-Reynolds on Owen-Reynolds's answer
http://answers.unity.com/comments/630514/view.html
Clever use of LookRotation can avoid trig altogether in most cases. But if you need/prefer trig, the final Quaternion rotations can be computed _from_ your own xyz-angles just fine. Ex: `base.rotation = Quaternion.Euler(0, ySpin, 0);` then `barrel.rotation=Quaternion.Euler(xUpTilt, ySpin, 0);` -- NOTE: order is y,x,z, so xUpTile is on local x, after the spin, which is perfect. Or use localRotation for the barrel. Where `xUpTilt` uses atan of the xz-hypotenuse and y.
Ai$$anonymous$$g a gun is also a pretty common topic here.Sun, 02 Feb 2014 15:12:24 GMTOwen-ReynoldsComment by Doodles on Doodles's answer
http://answers.unity.com/comments/630208/view.html
Apparently, using the quaternion approach has brought up a new question over how to copy only one axis of rotation to each of the two different parts the gun rotates on so that only one part rotates sideways and only one rotates vertically.Sun, 02 Feb 2014 01:44:50 GMTDoodlesComment by Owen-Reynolds on Owen-Reynolds's answer
http://answers.unity.com/comments/630197/view.html
Looking at the new(?) trig code above (or maybe I just didn't notice it before) could replace nearly all with: `Quaternion aimAngle = Quaternion.LookRotation(targPos-myPos);`.
If you look at the docs, they hint/say that changing individual eulerAngles, like your code does, can be buggy. They are computed from the quaternion, in a complex relationship.Sun, 02 Feb 2014 01:32:24 GMTOwen-ReynoldsComment by Doodles on Doodles's answer
http://answers.unity.com/comments/630045/view.html
Well, that helped part of the issue - your solution fixed the ai$$anonymous$$g at first making the gun aim correctly but the gun's aim eventually started to deviate when the target was moved higher or lowerSat, 01 Feb 2014 21:13:23 GMTDoodlesAnswer by Owen-Reynolds
http://answers.unity.com/answers/630026/view.html
Just a guess, your gun has (000) at the base, a few feet below the barrel? So that 1st line incorrectly computes the aim-angle from the wrong part of the gun?
Replace `transform.position` (the base) with `XAxis.position` (swivel point of the barrel) in the first line?
That's the same sort of glitch you get a lot in raycasting, where it's easy to mistakenly look from my feet to the enemy's feet.Sat, 01 Feb 2014 20:45:53 GMTOwen-Reynolds