I'm sure I am misunderstanding something about Unity vectors or something here. I am brand, brand new to Unity so this is part of the problem.
I am trying to make a simple atomic model and I am trying to model valence electrons.
I've got a game object with two children - the symbol (which is working perfectly), and a child electron.
If an atom has more than 1 valence electrons, I add those as additional child objects.
All of this is working just fine - except for one part. I have a default position for the original child valence electron, but when I try to add additional children and set their positions, they're not anywhere near where they should be.
For example:
My Model:
My base electron:
My additional electrons look like this:
And here is my output - obviously not right:
So here's my function to add additional electrons:
void addElectrons(Rigidbody2D atom)
{
AtomData.AtomData atomData = atom.GetComponent<Atom>().atomData;
if (atomData.ValElec > 1)
{
for (int i = 1; i < atomData.ValElec; i++)
{
GameObject electron = Instantiate(electron_obj, new Vector2(0.2f, 0), Quaternion.identity) as GameObject;
electron.name = "Electron " + (i + 1).ToString();
//electron.transform.localPosition = new Vector3(.02f, 0, 0);
electron.transform.localScale = new Vector3(.05f, .05f, 0);
electron.transform.parent = atom.transform;
}
}
}
I've tried Vector2 (currently shown above), a new Vector3 in transform.localPosition (shown and commented out), as well as in transform.position (not shown, but similar to localPosition).
What exactly am I doing wrong here? I am strongly guessing that I am misunderstanding the vector math or something here.