Comments and answers for "Using sin and cos to decompose a vector"
http://answers.unity.com/questions/964041/using-sin-and-cos-to-decompose-a-vector.html
The latest comments and answers for the question "Using sin and cos to decompose a vector"Answer by MateusSarmento
http://answers.unity.com/answers/964603/view.html
Yeah, thanks man! I got it. The right code is:
transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
float rot = transform.eulerAngles.y * Mathf.Deg2Rad;
float x = force * Mathf.Cos(rot)* Input.GetAxis("Vertical") * Time.deltaTime;
float z = force * Mathf.Sin(rot)* Input.GetAxis("Vertical") * Time.deltaTime;
rigidbody.AddForce(new Vector3(x,0,z));Mon, 11 May 2015 21:04:19 GMTMateusSarmentoComment by Bunny83
http://answers.unity.com/comments/964358/view.html
Uhm, if you want the forward direction (z direction) you have your sin / cos reversed ^^ You calculate the "right" direction (x direction). Also your rotation will rotate in the wrong direction.
To get the forward direction use:
x = Mathf.Sin(y_Radians)
z = Mathf.Cos(y_Radians)
To get the right direction you have to use
x = Mathf.Cos(y_Radians)
z = -Mathf.Sin(y_Radians)
Note the "-".
But as already mentioned using transform.forward or transform.right is usually way simpler ^^Mon, 11 May 2015 12:13:35 GMTBunny83Comment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/964348/view.html
But don't forget [Mathf.Deg2Rad][1] since Mathf.Sin takes an angle in [radians][2] while eulerAngles are in degree
MateusSarmento:
ps: transform.right actually gives you that vector that faces to the right of the object just like the one you calculated. Keep in mind that transform.right is affected by all rotations of this transform. You're method only rotates around the world y axis.
[1]: http://docs.unity3d.com/ScriptReference/Mathf.Deg2Rad.html
[2]: http://en.wikipedia.org/wiki/RadianMon, 11 May 2015 12:02:59 GMTBunny83Answer by tanoshimi
http://answers.unity.com/answers/964341/view.html
`transform.rotation.y` gives you the y component of a four-dimensional quaternion rotation. I suspect you wanted `transform.rotation.eulerAngles.y`.Mon, 11 May 2015 11:51:38 GMTtanoshimi