- Home /
transform.position
I am new to coding and unity, so the answer may be so simple.
Please see the code below. I am not sure why I am getting two different vectors.
using UnityEngine; using System.Collections;
public class test : MonoBehaviour { public Vector3 position; // Use this for initialization void Start () {
position = transform.position;
}
// Update is called once per frame
void Update () {
print (position); //I am getting >>> (4.5, 2.3, 0.0)
print (transform.position);//I am getting >>>(4.6, 2.3, 0.0)
}
}
Answer by catchthefloaty · Jun 15, 2014 at 06:32 AM
because the position you retrive in Start() doesnt cahnge over time. but transform.position does. im willling to bet one of those values always stays the same correct? adding : position = transform.position;
inside the start of UPdate() should resolve it.
Answer by sedativechunk · Jun 15, 2014 at 08:29 AM
Do you have another script or anything affecting the position of the object using this script? Like the other guy said, start is only called one time ever when the script first starts, and you are saving in a variable the starting values of the Vector 3. Update is called all the time. Somewhere down the line the coordinates of your object are changing and hence, they are not the same as the starting ones.
Your answer
Follow this Question
Related Questions
Transforming 2D object with respect to UI 1 Answer
Movement script for camera relative to where it looks 0 Answers
Why cant any operations be performed in camera when loaded from the previous scene? 0 Answers
Getting stuck in the ground while teleporting 0 Answers
How do I update the position of different prefabs to the current position? 0 Answers