- Home /
Rotate so VectorY points to another Vector3
I have point A and B, on a 2d plane(X,Y), when I'm at pointA I need to rotate my camera so it's localY axis points towards point B, once that's done I move the camera to pointB, when I reach pointB I'll need to rotate the camera back to face pointA (Yaxis pointing towards A). How can I get this correct angle?
Answer by CaioRosisca · May 26, 2014 at 05:15 PM
Vector 3 direcao = (new Vector3(nextNode.GetCoordinate().x,nextNode.GetCoordinate().y, myCamera.transform.position.z) - myCamera.transform.position).normalized;
myCamera.transform.up = direcao;
Here's the solution for it.
Answer by $$anonymous$$ · May 23, 2014 at 10:02 PM
C#
public Transform Player;
Vector3 Point;
public Transform A;
public Transform B;
void Update() {
if(transform.position != A.position && Player.poition == A.position)
{
Point = B.position;
}
else if(transform.poition != B.position && Player.position == B.position)
{
Point = A.position;
}
transform.LookAt(Point);
transform.position = Vector3.Lerp(transform.position, Point.position, / SomeTimeValue /);
}
tell me if this doesnt work :)
@$$anonymous$$ LookAt makes the Z axis point towards the point, I need the Y axis to do so, the movement works fine, I'm just having problem with the rotation, that also needs to be a Lerp, but that shouldn't be a problem once I can figure out the correct angle.
Your answer
Follow this Question
Related Questions
Arbitrary rotation around a point works except when up flips? 1 Answer
Rotate vector around vector? 2 Answers
Rotate 90 degrees over time with Parabolic Easing. 1 Answer
Rotate parent so child is facing a specific rotation 1 Answer
Need to know euler angles of Vector3 direction relative to other Vector3 direction 1 Answer