Dynamic texture

Hi guys! I’m new to this forum so if I posted this in the wrong section please direct me to the correct place for this. What I am trying to achieve is an endless road, what I tried at first was to have 3 planes which move towards the camera and when they hit a collider behind the camera it resets to a spawn point ahead of the camera. This worked but it only works for a few seconds and after a couple of resets, gaps start to appear between the planes. I am not sure if this is because of the slight time it takes to reset the plane or something else. Now I’m thinking that I should use dynamic textures to have the road texture moving past the car.

Any ideas on how to do this? I don’t mind if it’s a whole different way altogether, I just need to make an endless straight road.

Thanks

Post the code for how you are achieving the plane reset. I think your problem lies there and going down the road of dynamically creating textures is long and not probably worth the time to do here.

The colliders won’t work because you can’t be guaranteed that the hit will always register in the same amount of time, every time. Instead, your 3 planes idea would work if you used actual position values; i.e. when you reach -5 in z axis automatically move to exactly 5 in z and continue moving backwards, etc. There are a few things I can think of that might make it complicated, but it’s very much doable.

Using a dynamically created texture is probably not the way to go for this, as BigMisterB said it’s probably gonna be a lot more trouble than it’s worth. A much simpler way to do the effect you’re describing exists, at least if I’m thinking of it correctly. Simply have one long plane with a tiled road texture, and constantly slide the UVs of the plane so the texture appears to move towards the camera. You can do this endlessly as far as I know so you never have to reset them or anything.

private var respawnPoint : GameObject;
private var roadSpeed : float = 0;
private var roadController : GameObject;
private var roadcontrollerFound : boolean = false;
private var roadinfoScript : roadInfo;

function Start(){
	roadController = GameObject.Find("Road Controller");
	respawnPoint = GameObject.Find("Respawn Point");
	if(roadController == null){
		Debug.Log("roadController != \"Road Controller\" GameObject; Script:roadController.js");
	}else{
		roadcontrollerFound = true;
	}
	
	if(respawnPoint == null){
		Debug.Log("respawnPoint != \"Respawn Point\" GameObject; Script:roadController.js");
	}
	
	if(roadcontrollerFound){
		roadinfoScript = roadController.GetComponent(roadInfo);
		roadSpeed = roadinfoScript.speed;
		if(roadSpeed == 0){
			Debug.Log("Unable to locate speed; Script:roadController.js");
		}else{
			Debug.Log("Speed set to " +roadSpeed);
		}
	}
}

function Update () {
	roadSpeed = roadinfoScript.speed;
	gameObject.transform.Translate(0,0,roadSpeed * Time.deltaTime);
}

function OnCollisionEnter(collisionInfo : Collision){
	if(collisionInfo.gameObject.name == "Off Camera Collider"){
		gameObject.transform.position = respawnPoint.transform.position;
	}
}

Here is the my script for the road

Yeah I might go with just checking if the z is at a certain point and then reseting it and if that does not work I will try the texture solution. How would I achieve a moving road effect with the texture? Do I change the tiling?

I am a bit confused at this, none of this has to do with planes… :frowning:

However, there are modifications that need to be made to this script.

Assuming that each plane has a roadInfo component…

private var respawnPoint : GameObject;
var defaultRoadSpeed : float = 5.0;
private var roadSpeed : float = defaultRoadSpeed; // default road speed
private var roadController : GameObject;
private var roadcontrollerFound : boolean = false;
private var roadinfoScript : roadInfo;
 
function Start(){
	roadController = GameObject.Find("Road Controller");
	respawnPoint = GameObject.Find("Respawn Point");
	if(!roadController) return;
   
	if(!respawnPoint) return;
   
	roadinfoScript = roadController.GetComponent(roadInfo);
	if(roadinfoScript) roadSpeed = roadinfoScript.speed;
}

function Update () {
	var hit : RaycastHit;
	if(Physics.Linecast(transform.position + Vector3.up, transform.position - Vector3.up * 5, hit)){
		if(hit.gameObject != roadController){
			roadController = hit.gameObject;
			roadinfoScript = currentRoad.GetComponent(roadInfo);
		}
	}
	if(roadInfoScript)roadSpeed = roadinfoScript.speed;
	if(roadSpeed <= 0) roadSpeed = defaultRoadSpeed;
	gameObject.transform.Translate(0,0,roadSpeed * Time.deltaTime);
}

Thanks for taking the time to look over my script and even edit it! Sadly you lost me in the Update function…

I have made a new script which instead of checking for a collision just checks the position of the plane and then resets it and this seems to work but again gaps start to appear between the planes :frowning:
BTW the ‘Road Controller’ gameobject is an empty game object from which all the planes get the speed from and that is where the speed is increased.

Here is my new script, hopefully you can catch the mistakes that I have made while I try to implement the script you posted.

#pragma strict

private var roadController : GameObject;
private var roadInformation : roadInfo;

function Start () {
	roadController = GameObject.Find("Road Controller");
	if(roadController == null){
		Debug.Log("Unable to find Road Controller; Script: roadController.js");
	}else{
		roadInformation = roadController.GetComponent(roadInfo);
		if(roadInformation == null){
			Debug.Log("Unable to locate roadInfo.js component; Script: roadController.js");
		}
	}
}

function Update(){
	transform.Translate(0,0,roadInformation.speed * Time.deltaTime);
	if(transform.position.z >= 29){
		transform.position.z = -60;
	}
}

ok, assuming that each plane is 30 long you are simply pushing your character back. You are even pushing it back by whole numbers so you wouldnt actually see the change, you would assume that it is just pushing more blocks in front of it. Thats good thinking.

Now, what is all of this? LOL It doesnt seem like a very fun game yet. :wink:

This script gives the illusion that the road is endless even though its quite small but there are more ahead of it always

This works for a bit but then it makes small gaps again :frowning:
Do I have any other options for making an endless road or will I have to somehow make this work?

haha yeah its actually very boring, and my graphic designer is bugging me to hurry up so I am trying to get this done tonight.

how can “non-moving” planes create gaps?

they are moving…
they all have this script applied to them and the planes move towards the camera and then reset in front of it.

what is the roadInfo type ?