- Home /
Vector3 does not work
Hey, can someone help me understand what the problem is here with my vector3. I'm using a vector3 to change the position of a gameobject. In an update loop, I have the code 'boss.transform.position = new Vector3(8.406086f, boss.transform.position.y, -12.64066f);'. Y is not set to a value because this can change, however, the x and z values stay the same all the time. I would think by using this line of code the x axis of this object will always stay at '8.406086' and the z axis will always stay at '-12.64066', but it doesn't. For some reason the objects go to the coordinates of x = 18.25217 and z = -23.80132. If someone could tell me where I'm going wrong that would be great because I am super confused right now and have been looking at this for hours...
Answer by mauriciomb · Jul 03, 2018 at 05:02 PM
can you post your code? Also, is your object a child or parent of another object?
Thanks for the quick reply. Bit of an issue, my code is too long to post. :D It's 500 lines long. There isn't actually much to see here. The only time I ever use the 'boss' variable here is in that one line of code I posted before.

Also here is the structure of my hierarchy. The first 'Chapter1Boss' is the 'boss' gameobject in my code, so it's basically a child and parent object. Does this matter then? The 'Level10Intro' object also has an animation attached marked as Legacy where the y coordinate of 'boss' changes. I don't think that will affect it though.
Edit: Also before you ask, I definitly have referenced the right 'Chapter1Boss' in the script :D.
make sure that the child "Chapter1Boss" object position is set to (0,0,0) in the inspector.
That doesn't work sadly. The position of it was already (0,0,0) to begin with.
void Update ()
{
boss.transform.position = new Vector3(8.406086f, boss.transform.position.y, -12.64066f);
if (chapterNumberText != null)
{
chapterNumberText.text = chapterNumber.ToString();
}
if (levelNumberText != null)
{
levelNumberText.text = levelNumber.ToString();
}
if (endTheLevel == true && hasStartedAnimations == false)
{
StartCoroutine(StartAnimations());
hasStartedAnimations = true;
}
if (endTheLevel == true)
{
currentNode = null;
}
if (button1State == true)
{
button1On.SetActive(true);
button1Off.SetActive(false);
} else
{
button1On.SetActive(false);
button1Off.SetActive(true);
}
if (button2State == true)
{
button2On.SetActive(true);
button2Off.SetActive(false);
}
else
{
button2On.SetActive(false);
button2Off.SetActive(true);
}
if (button3State == true)
{
button3On.SetActive(true);
button3Off.SetActive(false);
}
else
{
button3On.SetActive(false);
button3Off.SetActive(true);
}
if (button4State == true)
{
button4On.SetActive(true);
button4Off.SetActive(false);
}
else
{
button4On.SetActive(false);
button4Off.SetActive(true);
}
if (button1State == true && button2State == true && button3State == true && button4State == true && playFinalAnimation == false)
{
winBossBattle = true;
StartCoroutine(WinBossBattle());
Debug.Log("Win");
playFinalAnimation = true;
}
}
Here's the Update() function at least but I don't think it will help in any way...
Your answer