1
\$\begingroup\$

so I've created a 2D sidescroller game, the technique I used is to keep the player on the same place, and move the obstacles towards him. I also offset the ground and backdrop constantly to create the illusion of player moving.

The ground texture is on a quad, and the texture wrap mode is set to repeat. In the editor everything is running fine as I wanted, however when I build it (WebGL), in the browser the ground doesn't seem as if it is set to Repeat but rather Clamp. Here's how it looks:

enter image description here

You can see from the left part of the image the ground doesn't repeat, the strange thing is that, after the game runs for a few more seconds it fixes, and then in a few seconds becomes like that again.

heres the code attached to the ground to keep it offsetting constantly:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Offset : MonoBehaviour {

public float scrollSpeed;
public Material mat;

private float offset;

// Use this for initialization
void Start () {
    mat = GetComponent<Renderer>().material;
}

// Update is called once per frame
void Update () {
    offset = Mathf.Repeat(Time.time * scrollSpeed, 1);
    mat.mainTextureOffset = new Vector2(offset, mat.mainTextureOffset.y);
}
}

What may I be doing wrong, and how can I fix it?

Thanks in advance!

\$\endgroup\$
5
  • \$\begingroup\$ based on my experience it's more convenient to use normal movement with spawning obstacles in front of character, so you don't need to sync other in-game objects with your ground texture offset \$\endgroup\$
    – Yevhen
    Commented Jan 14, 2017 at 19:16
  • \$\begingroup\$ Would that be less performance heavy? \$\endgroup\$
    – John Smith
    Commented Jan 15, 2017 at 7:49
  • \$\begingroup\$ why you use Time.time ? Time.deltaTime is alot better ( for me ) \$\endgroup\$ Commented Jan 15, 2017 at 13:33
  • 1
    \$\begingroup\$ Time.time only increases (which causes an increase in offset), where Time.deltaTime varies depending on the time in between frames \$\endgroup\$
    – John Smith
    Commented Jan 15, 2017 at 13:35
  • \$\begingroup\$ @VadimTatarnikov The performance different is slim. You should worry about performance only if you notice something wrong with it. At the end of the day, if it runs 0.0001 seconds faster, is it really worth it? \$\endgroup\$ Commented Jul 23, 2018 at 11:51

1 Answer 1

1
\$\begingroup\$

for texture scrolling you should use "Repeat" in import settings instead of "clamp"

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I have done that \$\endgroup\$
    – John Smith
    Commented Jan 15, 2017 at 7:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .