Answers for "Misbehavior with Quaternion.Slerp"
http://answers.unity.com/questions/658540/misbehavior-with-quaternionslerp.html
The latest answers for the question "Misbehavior with Quaternion.Slerp"Answer by joseques
http://answers.unity.com/answers/658868/view.html
After some hours of search in the forums I founded another way to acomplish what I trying to do using eulers but adding some math. It's weird that the other methods don't worked for me but thank you anyways guys!!
I used this code:
Vector3 mouse_pos = Input.mousePosition;
mouse_pos.z = 10; //Same as the object
Vector3 transform_ = Camera.main.WorldToScreenPoint(transform.position);
mouse_pos.x = mouse_pos.x - transform_.x;
mouse_pos.y = mouse_pos.y - transform_.y;
float angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
Now I need to smooth the movement, but that I can do it by myself.Sat, 08 Mar 2014 20:28:20 GMTjosequesAnswer by Bunny83
http://answers.unity.com/answers/658553/view.html
Your problem are those two lines:
newRotation.x = transform.rotation.x;
newRotation.y = transform.rotation.y;
The x,y,z,w values of a quaternion **are not** angles. [A quaternion is quite complex][1]. You shouldn't mess around with it's individual values since the whole quaternion is normalized and consists of an axis and a rotation.
If you want to limit the rotation to one axis, just make sure your direction is in the same plane. Since it seems to be a 2d game i guess the x-y-plane? in this case you just need to set the z value of the two vectors to the same value. Something like this:
MousePosition = Input.mousePosition;
MousePosition = Camera.main.ScreenToWorldPoint(MousePosition);
MousePosition.z = transform.position.z;
Quaternion newRotation = Quaternion.LookRotation(transform.position - MousePosition, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * moveSpeed);
Since we don't know the exact coordinate system of your world / airplane we can't tell you the exact solution.
[1]: http://en.wikipedia.org/wiki/QuaternionSat, 08 Mar 2014 10:06:07 GMTBunny83Answer by whydoidoit
http://answers.unity.com/answers/658551/view.html
You are messing with the x and y components of a quarternion which is undoubtedly not doing what you expect (those are not angles and do not only control rotation in those axes see this: http://unitygems.com/quaternions). You probably want to play with the eulerAngles on the rotation instead. Bear in mind that C# requires you to get the whole vector modify it and put it back again.
var rot = newRotation.eulerAngles;
rot.x = transform.eulerAngles.x;
rot.y = transform.eulerAngles.y;
newRotation.eulerAngles = rot;Sat, 08 Mar 2014 10:02:37 GMTwhydoidoit