- Home /
Align the Camera to the head of the drawn lines in vectorsity
Hi,
I'm using Vectrosity to draw3D continues lines on a flat surface (x,y). Imagine I'm drawing a path or graph on the screen out of a list of random vector3 points. I like to have the camera move with the head of the line and a little bit tilted so the head and portion of the last line can be seen as the line continue to be drawn exactly like a navigation software that shows the path. Further, I can't use auto follow or smooth follow scripts as the transform of the object belongs to the whole graph object and not only the last line of the drawn lines.
Right now I can move the camera on top of the headPos of the line but I can't figure out how to rotate the camera so the line always be towards up (e.g. like a navigation application). The current solution rotate the camera sometimes correctly but sometimes 180 degrees incorrect.
Vector3 headPos = myLine.points3[myLine.points3.Count - 1];
Vector3 beforeHeadPos = myLine.points3[myLine.points3.Count - 2];
Vector3 camPos = Vector3.Lerp(beforeHeadPos, headPos, 1.0f); ;
camPos.z = -600;
mainCam.transform.position = camPos;
Debug.Log(angleBetween(beforeHeadPos, headPos));
//ROTATION ISSUE
mainCam.transform.rotation = Quaternion.Euler(0, 0, 90 + angleBetween(beforeHeadPos, headPos));
float angleBetween(Vector3 v1, Vector3 v2) {
return Mathf.Atan((v2.y - v1.y) / (v2.x - v1.x)) * 180 / Mathf.PI;
//return (angle < 0 ? angle+360 : angle);
}
ok I think I found a workaround! But please comment on my code anyway especially how can I title the camera a bit. The camera rotation jitters between 90 degrees (upward) and 180 degree (downward) for some reason. This can be fixed by adding 0.01 degree to the result of angleBetween. I also swap the parameters to the function. Further I replaced Eureler with AngleAxis. That doesn't change anything.
mainCam.transform.rotation = Quaternion.AngleAxis(91 + angleBetween(headPos, beforeHeadPos), new Vector3(0,0,1));
float angleBetween(Vector3 v1, Vector3 v2) {
float angle = $$anonymous$$athf.Atan2((v2.y - v1.y), (v2.x - v1.x)) * 180 / $$anonymous$$athf.PI;
return (angle < 0 ? angle+360 : angle);
}
Your answer
Follow this Question
Related Questions
How can I turn the direction of bicycle in Unity? 3 Answers
how do i make first person character rotate left and right along with camera? 0 Answers
Virtual Reality - Android Gyroscopic Camera - Pitch and Roll Issues. 1 Answer
How can I create a normal TPS (third person shooter) camera orbit with collision ? 1 Answer
When I rotate the Camera XYZ coordinat arrows rotate too How to prevent that 2 Answers