- Home /
How to Apply time.deltaTime in transform.position
someone know how can i apply "time.deltatime" in this code?
transform.position = new Vector3(Move_X.transform.position.x, transform.position.y, transform.position.z);
Answer by DaveA · Jun 17, 2013 at 07:22 PM
Were you aware of the online documentation? http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html
Answer by AntiLunchBox · Jun 17, 2013 at 07:24 PM
transform.position = Vector3.Lerp(transform.position, Move_X.transform.position, Time.deltaTime * (SOME_X_FACTOR_YOU_WANT));
I figured that's what you're looking to actually do.
I need to make it smooth on the X axis this way: $$anonymous$$ove_X.transform.position.x
exe:
transform.position = Vector3.Lerp(transform.position, $$anonymous$$ove_X.transform.position.x, Time.deltaTime * 5);
Okay then use: transform.position.x = $$anonymous$$athf.Lerp(transform.position.x, $$anonymous$$ove_X.transform.position.x, Time.deltaTime * 5f);
gave error:
: error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable
Okay, it's as the error describes-- so you'll have to store the value, so do:
Vector3 thisPosition = transform.position;
thisPosition.x = $$anonymous$$athf.Lerp(thisPosition.x, $$anonymous$$ove_X.transform.position.x, Time.deltaTime * 5f);
transform.position = thisPosition;
you can't modify parts of transform.position without replacing the whole vector3
Your answer
Follow this Question
Related Questions
how do i make this to a negative (ShopRespawn < 180)? 1 Answer
Gameobject moving faster at higher framerates? Using Time.deltaTime 2 Answers
Framerate, Time.deltaTime and moving the character. 1 Answer
Unity Simple Clock Tutorial with custom time? 1 Answer
Using Time efficiently regardless of current frame rate. 0 Answers