- Home /
Rotating a LineRenderer
Hello everybody,
Before explaining my problem, i'm gonna explain you the context.
So, i want to able to select mesh triangles with a circle cursor. And it should colors the triangle touched.
My problem is the creation of the circle.
I means, this code, creates perfectly my circle :
void Start()
{
LineRenderer line = GameObject.FindWithTag("MainCamera").AddComponent<LineRenderer> ();
line.material = GetComponent<WireFrameLineRenderer>().LineMaterial;
line.SetColors (Color.white, Color.white);
line.SetWidth (0.2F, 0.2F);
line.SetVertexCount(64);
//line.useWorldSpace = false;
}
public void CreateCircleAroundMousePointer ()
{
LineRenderer line = GameObject.FindWithTag("MainCamera").GetComponent<LineRenderer> ();
Vector3 mouse = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 20.0F));
int r = 1;
int i = 0;
for(double theta = 0; theta < 2 * Math.PI +0.1; theta += 0.1) {
double x = r * Math.Cos(theta);
double y = r * Math.Sin(theta);
float x1 = (float) x;
float y1 = (float) y;
Vector3 pos = new Vector3(x1 + mouse.x, y1 + mouse.y, mouse.z);
line.SetPosition(i, pos);
i+=1;
}
}
The circle follows my cursor very well, but it doesn't rotate...
So i tried to added it to the mainCamera and i hoped it would rotate with it, but i doesn't....
My problem is that my circle doesn't rotate when my camera is rotating around the main object. So when i'm facing it, the circle is perfectly where i need it to be but when i'm at a 90 degree angle, i just see a line (a circle view from side).
Thx for your help,
Actually, my camera is rotating around a gameobject wich is the center of the object that i need to see.
I don't really remember how line renderers work, I've been using my own system to draw lines for too long. But IIRC, there's a toggle to deter$$anonymous$$e whether the line renderer uses local or world space. (absolute or relative) If I'm not mistaken, the most expedient solution would involve using local space coordinates to create the desired shape, then billboarding the line renderer's object and placing it at the mouse position in world space.
Your alternative involves some slightly more expensive and considerably more confusing math to build the circle with world-space points that respect the camera's orientation relative to the line renderer object. Unless you have a great reason to do otherwise, the best approach to a problem is often the most convenient.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Rotate Bezier Curve around object following mouse position 0 Answers
slowly rotate a object *need quick fix* 0 Answers