- Home /
The question is answered, right answer was accepted
help on 2d platform movement
hi, am doing a top down platform game, where i have two quads as road, which i have to reuse it by changing its position back to origin when it moves out of camera.i have already done a basic movement script for this but i get empty space between the quads when each one moves to the origin. need help on how to make the platform reusable or is there any other technique to achieve this sort of movement. the script is below.
using UnityEngine; using System.Collections;
public class roadScript : MonoBehaviour {
public float speed = 2.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.down * speed);
if(transform.position.y < -142.0f)
{
transform.position = new Vector3(0.0f, 201.0f, 25.0f);
}
}
}
Answer by kevinspawner · Mar 17, 2015 at 10:41 AM
This script will tile once the end point is reached. Feel free to edit the tile size. Hope it helps.
{
public float scrollSpeed; public float tileSizeY;
private Vector3 startPosition;
void Start ()
{
startPosition = transform.position;
}
void Update ()
{
float newPosition = Mathf.Repeat(Time.time*scrollSpeed,tileSizeY);
transform.position = startPosition + Vector3.up*newPosition;
}
}
Follow this Question
Related Questions
How to find what you're looking for in the Documentation? 3 Answers
What is Cloud Build? 1 Answer
Starting Out in Game Development 5 Answers