- Home /
Time.deltaTime problem on scrolling background material.
Ok so I have this endless runner game where I solved the background parallax with several child objects. Each childobject has a material which scroll with a portion of the speed of the camera. Now the problem I have is:
If i declare the scrolling speed just once the background will appear to stutter a bit since the camera speed increases each second.
void Start () {
gameController = GameController.instance;
//Set speed first time
for (int i = 0; i <= gameObject.transform.childCount - 1; i++)
{
speed.Add(GameController.instance.xVelocity * Time.deltaTime * 0.2f * i);
}
}
// Update is called once per frame
void Update () {
for (int i = 1; i <= gameObject.transform.childCount - 1; i++)
{
offset = new Vector2(-speed[i] * Time.time, 0);
//Move the different layers at different speeds
gameObject.transform.GetChild(i).GetComponent<Renderer>().material.mainTextureOffset = offset;
}
If i change the scrolling speed each frame by multiplying with Time.deltaTime I get even more stutter.
void Update () {
for (int i = 0; i <= gameObject.transform.childCount - 1; i++)
{
speed[i] = (GameController.instance.xVelocity * Time.deltaTime * 0.2f * i);
}
for (int i = 1; i <= gameObject.transform.childCount - 1; i++)
{
offset = new Vector2(-speed[i] * Time.time, 0);
//Move the different layers at different speeds
gameObject.transform.GetChild(i).GetComponent<Renderer>().material.mainTextureOffset = offset;
}
It's almost as if the deltaTime becomes negative some frames. Do you have any idea why the Time.deltaTime causes the stuttering? Alternatively do you know any solution? Thanks a lot for your time.
Your answer
Follow this Question
Related Questions
How do you make an Accurate Timer on iphone 1 Answer
How can i keep making the SendMessage repeat as long as the boolean is true 1 Answer
Why does the time in Vector3.Lerp effect my position? 1 Answer
Periodically updating frame conditionally - Time.deltaTime 1 Answer
Yet another Time.deltaTime question 2 Answers