Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Draw Angle between 2 points in Mesh

Discussion in 'Scripting' started by mpastor_unity, Jul 17, 2023.

  1. mpastor_unity

    mpastor_unity

    Joined:
    Jul 17, 2023
    Posts:
    2
    I want to draw the Angle between point B and point C in point A. But all these points move dynamically, so they might have different values in all axis. How can I draw a mesh for this?

    upload_2023-7-17_14-35-15.png
     
    Last edited: Jul 17, 2023
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,718
    There is no point in sharing these numbers here with us.

    If the points are moving constantly, then you just have to modify the mesh each frame as they move, using their current position each frame, that's all. If you can do it once, you can do it every frame (in LateUpdate)
     
    Bunny83 likes this.
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,588
    There is a lot of ressources on how to create a custom mesh. Make sure to draw the triangle clockwise from view direction, or it wont show. Redraw the mesh when these values change.
     
    Bunny83 likes this.
  4. mpastor_unity

    mpastor_unity

    Joined:
    Jul 17, 2023
    Posts:
    2
    Yeah, I know but it was so people have the same values as I do in the example, to try to achieve the mesh.
     
  5. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Connect : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         Vector3[] points=new Vector3[3];
    8.         points[0]=Random.insideUnitSphere*5f;
    9.         for (int p=0;p<points.Length-1;p++)
    10.         {
    11.             points[p+1]=Random.insideUnitSphere*5f;
    12.             GameObject cyl=GameObject.CreatePrimitive(PrimitiveType.Cylinder);
    13.             float length=Vector3.Distance(points[p+1],points[p]);
    14.             cyl.transform.localScale=new Vector3(0.1f,length/2f,0.1f);
    15.             cyl.transform.position=points[p]+(points[p+1]-points[p])/2;
    16.             cyl.transform.up=points[p+1]-points[p];
    17.         }
    18.     }
    19. }
     
  6. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    Line renderer version:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Connect : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         LineRenderer lr=gameObject.AddComponent<LineRenderer>();
    8.         lr.material = new Material(Shader.Find("Sprites/Default"));
    9.         lr.material.color=Color.green;
    10.         Vector3[] points=new Vector3[3];
    11.         lr.positionCount=points.Length;
    12.         lr.widthMultiplier=0.1f;
    13.         for (int p=0;p<points.Length;p++)
    14.         {
    15.             points[p]=Random.insideUnitSphere*5f;
    16.             lr.SetPosition(p,points[p]);
    17.         }
    18.     }
    19. }