So what I’m trying to do is make a game with a skill tree, and I want to make lines in between each skill so the player knows which upgrades to get in which order, however unity doesn’t have a simple line drawing function for this. So I am using a rectangle to put one end under one skill and the other end under the other skill, and so I am doing this by taking the coordinates of both skills and adjusting the ends of the rectangle to it. However, I also need to tilt the rectangle to adjust to the two skills, because my skill tree isn’t just straight up, down, left and right. I need the angle of the rectangle to be adjusted to each set of skill images, no matter where each one is placed.
I will be making many different skill trees for many different classes, so I need the ability to be able to instantly load lots of lines, but I am also going to be designing each skill tree’s skills in specific ways for each one, so i need to make the skills myself then have the lines auto adjust to the skills.
So originally I had thought of just finding the angle opposite the hypotenuse, and using that to adjust the line, and it would’ve worked if the angle the hypotenuse was opposite of didn’t change. For instance (Triangle calculator, triangle solver SSS (side side side)), if I put in A(592,252), B(-184,252), and C(0,0), then the hypotenuse is straight down. But if I switch the coordinates, so A(592,252), B(0,0), and C(-184,252), then the hypotenuse is now top right, so the angle I need to get is different (angle B instead of angle C). So how do I know which angle to use and when? Or do I need to change the equation entirely?
Thanks
//Skill Tree------------
public Dropdown mainClass;
public Dropdown subClass;
public GameObject originalSkillGO;
public GameObject skillsFolder;
public GameObject skillLine;
public void MainClassChanged()
{
if (mainClass.options[mainClass.value].text == "Claymore") //More info https://answers.unity.com/questions/1082554/how-to-change-text-in-dropdown-menu-in-c-during-ru.html
{
subClass.options.Clear();
subClass.options.Add(new Dropdown.OptionData() { text = "Miria" });
subClass.options.Add(new Dropdown.OptionData() { text = "Clare" });
subClass.options.Add(new Dropdown.OptionData() { text = "Ophelia" });
}
}
public void SubClassChanged()
{
if(subClass.options[subClass.value].text == "Miria") //since each individual character will have their own seperately designed skill tree, I will need to make seperate ones (I can clean this up later)
{
//List of skills for each character below
SkillTreeSkillButtons.Clear();
//Also need to delete all gameobjects of skills and remake them every time you load a new character
for (int i = 0; i < MiriaSkills.Count; i++)
{
GameObject newSkilLGO = (GameObject)Instantiate(originalSkillGO); //Creation of a new Skill,
newSkilLGO.name = "Skill";
newSkilLGO.transform.parent = skillsFolder.transform;
newSkilLGO.GetComponent<RectTransform>().localPosition = MiriaSkillsTransform[i];
newSkilLGO.GetComponent<RectTransform>().localScale = new Vector3(.5f, .5f, .5f);
SkillTreeSkillButtons.Add(newSkilLGO);
SkillTreeSkillButtons[i].GetComponent<SkillTreeSkillSlot>().skill = MiriaSkills[i];
SkillTreeSkillButtons[i].GetComponent<SkillTreeSkillSlot>().RefreshSkill();
}
for (int i = 0; i < SkillTreeSkillButtons.Count; i++)
{
GameObject newSkilLGO = (GameObject)Instantiate(originalSkillLine); //Creation of a new skill line, will finish up this section later
}
}
}
public List<GameObject> SkillTreeSkillButtons = new List<GameObject>(); //This is a list of the buttons that are created which will have the individual skill on that I can buy.
public List<Skill> MiriaSkills = new List<Skill>(); //The Scriptable object of each individual skill (this will be attached to the skilltreeskillbutton game objects)
public List<Vector3> MiriaSkillsTransform = new List<Vector3>() {}; //The coordinates of where I want each skill to go in the skill tree (designing myself)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SkillTreeBGLine : MonoBehaviour
{
public GameObject skill1;
public GameObject skill2;
Vector3 size;
public void Move()
{
var skillOne = skill1.GetComponent<RectTransform>().localPosition; //Map Tab
var skillTwo = skill2.GetComponent<RectTransform>().localPosition;
size.x = (float)(Mathf.Abs((skillOne.x - skillTwo.x) /100f) + 1); // The Length
size.y = .2f;
size.z = 1f;
this.GetComponent<RectTransform>().localScale = size; //width, height
this.GetComponent<RectTransform>().localPosition = new Vector3(((skillOne.x + skillTwo.x) / 2), ((skillOne.y + skillTwo.y) / 2), 0f); //x,y,z
var a = Mathf.Sqrt(Mathf.Pow(skillTwo.x - 0f, 2) + Mathf.Pow(skillTwo.y - 0f, 2));
var b = Mathf.Sqrt(Mathf.Pow(skillTwo.x - skillOne.x, 2) + Mathf.Pow(skillTwo.y - skillOne.y, 2));
var c = Mathf.Sqrt(Mathf.Pow(skillOne.x - 0f, 2) + Mathf.Pow(skillOne.y - 0f, 2));
print("a" + a);
print("b" + b);
print("c" + c);
this.GetComponent<RectTransform>().eulerAngles = new Vector3(0, 0, -1f * (Mathf.Acos((Mathf.Pow(a, 2) + Mathf.Pow(c, 2) - Mathf.Pow(b, 2)) / (2f * a * c))) * (180f / Mathf.PI));
print("line angle" + (Mathf.Acos((Mathf.Pow(a, 2) + Mathf.Pow(c, 2) - Mathf.Pow(b, 2)) / (2f * a * c))) * (180f/Mathf.PI));
//h = b * sin[arccos((a2 + b2 - c2) / (2ab))], B = arcsin (h / c)
}
}

