- Home /
How to make the background move for a nice effect.
I am making a game right now and I want that the background moves slowly to the left and it starts at these positions X -2.981993, Y -0.4566485, Z = 1. And it must goes slowly to these positions X -2.981993, Y -0.4566485, Z = -4. And when it does again the background clones or dissapear himself and then it goes again to these positions X -2.981993, Y -0.4566485, Z = 1. But when it does it must not be like that the player can see that this is happening :) I hope you are understanding it. So it's like background goes left slowly and then again it spawns on new position en it repeats itself. But I don't want that the background clones itself otherwise you will have 40 backgrounds and the game will be lagg hard.
PS: I am sorry for my bad English hope that you understand what I ment.
Thank in advance.
Answer by simco500 · Jan 20, 2013 at 02:52 AM
It is really easy done by just scrolling the texture smoothly. Here is the code:
var ScrollSpeed : float = 0.5;
function Update () {
var offset : float = Time.time * ScrollSpeed;
renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
}
Also explained HERE
$$anonymous$$any thanks to simco500 it fixes my problem.
Answer by robertbu · Jan 19, 2013 at 10:48 PM
Here is a starter script. Set the Start, End, and Distance to travel per second in the inspector:
public class MoveSlowly : MonoBehaviour {
public Vector3 v3StartPos;
public Vector3 v3EndPos;
public float fDistPerSecond = 0.1f;
void Start () {
transform.position = v3StartPos;
}
void Update () {
transform.position = Vector3.MoveTowards(transform.position, v3EndPos, fDistPerSecond * Time.deltaTime);
if ((v3EndPos - v3StartPos).magnitude < .000001f)
transform.position = v3StartPos;
}
}
Answer by helloiam · Jan 20, 2013 at 02:51 AM
I will try it, thanks. To the others post if you know better :D