Comments and answers for "Vector3.RotateTowards Problem"
http://answers.unity.com/questions/1662037/vector3rotatetowards-problem.html
The latest comments and answers for the question "Vector3.RotateTowards Problem"Comment by Bonfire-Boy on Bonfire-Boy's comment
http://answers.unity.com/comments/1664422/view.html
Having said that, `target` is also private and not assigned to. So presumably you're not using the code unmodified as it'd be throwing null reference exceptions.Tue, 10 Sep 2019 11:41:09 GMTBonfire-BoyComment by Bonfire-Boy
http://answers.unity.com/comments/1664421/view.html
If you're trying to use that code unmodified then seems to me there's an obvious issue in that `speed` is private and not assigned to, so will have the default value of zero. I would suggest a) making it public so you can tweak it and b) setting its default value to 1.0.Tue, 10 Sep 2019 11:39:34 GMTBonfire-BoyComment by DCordoba on DCordoba's answer
http://answers.unity.com/comments/1664415/view.html
hello
if you objetc that rotate have a transform you can use [Transform.RotateAround][1] and you have solved the problem
Otherwise you need a right, forward, and up vector (if you have just 2, example forward and up, like 3 point plane, you can use [Vector3.Cross][2] to get the right)
taking the current angle you can use sine and cosine to get the position on (x,y) relative to the angle
suppose to you will store the desired position in `currPos` (current position) variable, point to pivot in `centerPoint` and distance to the point in `distance`, lets draw it like a vector on a 2d plane formed by the point center (as the 0 on the plane), the right(as the x axis) and forward (as the y axis)
to see the position (x, y) of certain rotation + distance to center on a plane, you need to perform the next calculus, [source][3]
(cosine(angle), sine (angle))*distance to center
to do this on 3d plane using forward and right vectors you just have to multiply sine, and cosine results (`float`), by the the axis vectors normalized (`Vector3`) and the multiply the result to the distance, more clearly I think expressed in code
//initialize var
Vector3 currPos = Vector3.zero;
//get the position on x axis (cosine) and multiply it by right axis
//(right direction to the plane on 3d space where the circle rotate)
currPos = right.normalized * Mathf.Cos(angle);
//get the position on y axis (sine) and multiply it to forward axis and sum to the previous
currPos += forward.normalized * Mathf.sin(angle);
//mutiply that by the desired distance around the point
currPos *= distance;
// translate de vector to the center, adding it
currPos += centerPoint;
so, how to get forward and right vectors? if you are rotating around a transform, use the native forward and right (or up if you need)
if you have a axis that you define the normal to the plane where the "circle of rotation" will be "drawed" you can use cross product to get two perpendiculars easy
Vector3 nonParallelVector = axis;
Vector3 right:
Vector3 forward;
//setting a non parallel vector of axis, to do a croos product and get first perpendicular
if(Mathf.Approximately(axis.x, 0)) //x == 0 using float...
nonParallelVector.x = 1;
else (){
nonParallelVector.y = nonParalelVector.x;
nonParallelVector.x = 0;
}
right = Vector3.Cross(nonParallelVector, axis); //get perpendicular to two non paralel vectors
forward = Vector3.Cross(right, axis); //get the last perpendicular to the axis vectors
if you need a random forward and right, you can take two different points, get the vectors from center and calculate two cross products, etc
[1]: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html
[2]: http://docs.unity3d.com/ScriptReference/Vector3.Cross.html
[3]: https://en.wikipedia.org/wiki/File:Sinus_und_$$anonymous$$osinus_am_Einheitskreis_1.svgTue, 10 Sep 2019 11:29:05 GMTDCordobaAnswer by Lawrence57
http://answers.unity.com/answers/1664111/view.html
I'm trying to achieve specialized movement in a circular direction around a point. For example, the character moves from in front of the point to the right of the point while maintaining their distance from the point. After some struggling with complicated math, I got to thinking I might be able to use Vector3.RotateTowards with the angleRadiansDelta calculated.Mon, 09 Sep 2019 09:12:02 GMTLawrence57