# Best way to solve this

Hi all!

Before you all read this I must warn that my background is mainly artistic. I have been touching and making scripts in c# only three months ago, so please forgive me in advance for any error I could have done.

The relevant elements of my problem are the next ones:

• GameObject Planet
Image Ring. // it’s a png texture of a white circle, transparent in the center
• LineRenderer lineRenderer

This is How the elements are arranged in the hierarchy:

Expected behaviour:

Actual behaviour:

How you see, my LineRenderer is visible behind the ring in the actual behaviour, but in the expected behaviour Its invisible while inside the ring. ¿Maybe with mask? ¿Maybe with colliders + raycast? ¿Or maybe with hard maths and line + circle equations?

I’m pretty rokkie and have no clue of how make this. Thank you in advance for any help!

That’s a fun little exercise
I gave it a go and here’s my solution for selecting the starting planet. The first position of the linerender is calculated by normalizing the start/end vectors (where start is the planet and end is the mouse) and then slightly decreasing its result. If you have bigger planets, just increase the 0.75f value.

With this I hope you’ll have less trouble making the destination planet to work

``````public class PlanetSelectorScript : MonoBehaviour {

LineRenderer lineRenderer;
bool PlanetClicked = false;
private Transform planet;
private Vector3 mousepos;

void Start(){
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.SetWidth(0.1f,0.1f);
planet = transform;
}

void Update(){
if (PlanetClicked && planet != null) {
mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousepos.z = 0;

lineRenderer.SetPosition(0, transform.position - ((planet.position - mousepos).normalized *  0.75f) );
lineRenderer.SetPosition(1, mousepos );

}
}

void OnMouseUp () {
PlanetClicked = true;
}
}
``````

@Interdictor - Hi, I’d go for UI elements, instead of using linerenderer. You don’t most likely want to mix your UI / HUD items with world items.

@Trav3l3r Thank you a lot! I have adapted this line and seems to work a lot more similar to the expected!

``````    lineRenderer.SetPosition (0, planet.position - ((planet.position - mousepos).normalized * 0.75f));
``````

@eses yeah, I friend of mine told me that LineRenderer is not suposed to work with UI. I should learn to make lines only with canvas elements.

This is a very shameless plug, but my Asset Primitive UI can do exactly that. It’s not as specialized as some other line drawing solutions out there (I personally like Vectrosity as well), but it creates UI dynamic elements on the fly and I think it may be a good fit here. =)

Also a quick tip for the problem at hand: If you make your ring image so that the ring touches the boundaries of the image it’s probably a bit easier to make radius <—> sprite size conversions, which would help here (so you don’t have to use “magic numbers” like 0.75f). It also gives you the most bang for your buck in terms of resolution.