So I want to have some clouds that slowly move over time and repeat with the camera and I’m have trouble. Should I also have a parallax script on the clouds or not? The cloud script I have right now doesn’t move with the camera and I just don’t like it too much, any other suggestions on how to do this? This is what I have at the moment.
{
private float speed;
public float minSpeed;
public float maxSpeed;
public float minX;
public float maxX;
private void Start()
{
speed = Random.Range(minSpeed, maxSpeed);
}
private void Update()
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
if (transform.position.x > maxX)
{
Vector2 newPos = new Vector2(minX, transform.position.y);
transform.position = newPos;
}
}
}
I did repeating terrain script before. If you only change the terrain for clouds it would work just fine i believe. I have 3 terrains with size 500f which always append themselves in front of each other.
And If you want the clouds to move with camera/player child the clouds to camera and restrict rotation in editor.
public Transform terrain1;
public Transform terrain2;
public Transform terrain3;
public float speed = 15f;
public float terrainSize = 500f;
public float numberOfTerrains = 3f;
public float origXlocation = -250f;
public float origYlocation = -5f;
float z1;
float z2;
float z3;
Vector3 newposition;
// Update is called once per frame
void Update()
{
newposition = transform.forward * Time.deltaTime * speed;
terrain1.transform.position += newposition;
terrain2.transform.position += newposition;
terrain3.transform.position += newposition;
//Debug.Log(terrain1.transform.position.z);
z1 = terrain1.transform.position.z;
z2 = terrain2.transform.position.z;
z3 = terrain3.transform.position.z;
//go to the end of 1st terain warp back
if (z1 >= terrainSize)
{
z1 = z1 - (numberOfTerrains* terrainSize);
terrain1.transform.position = new Vector3(origXlocation, origYlocation, z1);
}
if (z2 >= terrainSize)
{
z2 = z2 - (numberOfTerrains * terrainSize);
terrain2.transform.position = new Vector3(origXlocation, origYlocation, z2);
}
if (z3 >= terrainSize)
{
z3 = z3 - (numberOfTerrains * terrainSize);
terrain3.transform.position = new Vector3(origXlocation, origYlocation, z3);
}
}