Search Unity

Circle Under Objects

Discussion in 'Scripting' started by gamesurgeon, Apr 28, 2011.

  1. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
  2. fededevi

    fededevi

    Joined:
    Jun 11, 2010
    Posts:
    29
    You can use LineRenderer depending on what exactly you want... I used it a while back for this purpose.

    Code (csharp):
    1.  
    2.         selectionBox  = new GameObject();
    3.         selectionBox.transform.parent = transform;
    4.        
    5.  
    6.         lineRenderer= selectionBox.AddComponent<LineRenderer>();
    7.         lineRenderer.SetVertexCount (70);
    8.         lineRenderer.useWorldSpace = false;
    9.         int index = 0;
    10.         for (float i = 0f; i < Mathf.PI * 2f; i = i + (Mathf.PI * 2f) / 60f)
    11.         {
    12.             lineRenderer.SetPosition (index++, new Vector3 (transform.position.x + radius * Mathf.Sin (i),transform.position.y + radius * Mathf.Cos (i), 0f));
    13.         }
    14.         lineRenderer.SetPosition (index++, new Vector3 (transform.position.x + radius * Mathf.Sin (0f),transform.position.y + radius * Mathf.Cos (0f), 0f));
    15.         selectionBoxRenderer.SetVertexCount (index);
    16.  
    you need to recalculate the points every frame if you want it to follow tghe terrain
     
  3. CgRobot

    CgRobot

    Joined:
    Jan 4, 2011
    Posts:
    175
    Could you do some kind of texture projection or maybe a decal? I do not know how to do it, but maybe somebody else does. I think you need unity pro though to use decals.
     
  4. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    531
    Use a projector placed as a child of the character, facing down.

    Set it to ignore all layers except the terrain, and it'll project the circle texture down on the ground.

    It won't be off the ground, or 3D, for that matter, but it's the simplest method of doing that effect I think.

    Cheers
     
  5. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
    Harvester, your implementation works like a charm.

    Thanks so much for all the ideas!