- Home /
 
How can i make the circle to be drawn not from the top but from the camera view top ?
What i mean is that from the camera that the view is from the top i want to rotate the circle so it looks like the circle is on the ground. Not to rotate or change the camera position but to rotate the circle i think on the Z axis ?
This is how it looks like from the top view:

And the code:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DrawCircle : MonoBehaviour
 {
     public int segments;
     public float xradius;
     public float yradius;
     LineRenderer line;
 
     void Start()
     {
         line = gameObject.GetComponent<LineRenderer>();
 
         line.positionCount = segments + 1;
         line.useWorldSpace = false;
         CreatePoints();
     }
 
     private void Update()
     {
         if (Input.GetAxis("Mouse X") < 0)
         {
             xradius = xradius + 5;
             CreatePoints();
         }
         if (Input.GetAxis("Mouse X") > 0)
         {
             xradius = xradius - 5;
             CreatePoints();
         }
     }
 
     void CreatePoints()
     {
         float x;
         float y;
         float z = 0f;
 
         float angle = 20f;
 
         for (int i = 0; i < (segments + 1); i++)
         {
             x = Mathf.Sin(Mathf.Deg2Rad * angle) * xradius;
             y = Mathf.Cos(Mathf.Deg2Rad * angle) * yradius;
 
             line.SetPosition(i, new Vector3(x, y, z));
 
             angle += (360f / segments);
         }
     }
 }
 
               I want to rotate the circle so it looks like it was drawing on the terrain. Maybe i should use somehow Ray and draw the circle already on the terrain ?
But not sure how to use it with my code:
 RaycastHit hit;
             Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit, 1000))
             {
                 Vector3 hitpoint = hit.point;
 
               It's better if i could make the circle to be drawn on the terrain it self and then using the mouse with the ray to change the xradius +5 and - 5
Answer by wornTunic · Sep 11, 2017 at 02:00 PM
You could either rotate it by 90 deg on Z axis, or, in your circle-drawing script, you could change it so the points are on x and z axes, while the y is fixed. Something like this:
  void CreatePoints()
  {
      float x;
      float y = 0f;
      float z;
 
      float angle = 20f;
 
      for (int i = 0; i < (segments + 1); i++)
      {
          x = Mathf.Sin(Mathf.Deg2Rad * angle) * xradius;
          z = Mathf.Cos(Mathf.Deg2Rad * angle) * yradius; //this should probably be called zradius in this case
 
          line.SetPosition(i, new Vector3(x, y, z));
 
          angle += (360f / segments);
      }
  }
 
               Note: You might need to tweak that y to something greater than zero, or if you want it to be on the ground, raycast to the ground to determine your y position.
Your answer