hey guys, so i try to move my object to certain coordinat, heres the code
if (gameObject.transform.position.x <= -49.7f )
{
gameObject.transform.position = new Vector3(49.08f, 1f, 0.0f);
}
while the object correctly move to the X coordinat i wanted, but not the Y coordinat, it always move to 0.404 on Y coordinat, it drives me mad, i already try everything but no avail, hope anyone can help
edit :
heres the complete script
void Update ()
{
this.gameObject.transform.Translate(Vector3.left * platspeed * Time.deltaTime);
if (gameObject.transform.position.x <= -49.7f )
{
gameObject.transform.position = new Vector3(49.08f, 1f, 0.0f);
}
}
> gameobject.transform.position not working correctly No, YOU do something wrong. Stop blaming Unity. Provide your whole script please. You surely move the object somewhere else
– HelliumTry transform.x -= platspeed * Time.deltaTime; instead of this.gameObject.transform.Translate(Vector3.left * platspeed * Time.deltaTime); and tell me if it works.
– SideAs the documentation says : > If relativeTo is left out or set to Space.Self the movement is applied relative to the transform's local axes. Are you sure the rotation of your object is (0,0,0) ? If not, try transform.Translate(Vector3.left * platspeed * Time.deltaTime, Space.World);
– HelliumI am having the same issue with a similar piece of code. In fact, if I do the following: gameObject.transform.position = new Vector3 (0.0f, 0.0f, 0.0f); The object moves!! (even though the object started at (0,0,0). Can anyone help?
– zedsmith52Have you tried using void LateUpdate() instead of void Update() ? Other scripts may have been setting their own values for the transform(i.e. Character controller, NavMeshAgent).
– ThatIntermediateAj