Hello. I want to make my game similar to this (27-37 seconds), the player will be going through a tunnel with obstacles all around it. Rather than have the player controlled object traveling through an entire modeled tunnel and looping around it, the player is going to stay in the same place, the tunnel is going to rotate and be constantly instantiated/destroyed to create a scrolling effect and the obstacles are going to be randomly placed. I have some questions about how I would do some of that:
1: If the tunnel is constantly being instantiated, how would I also instantiate the obstacles on the tunnel(how could I make sure they are attached to the tunnel)?
2: How can I make sure that there are no gaps in the tunnel (since the multiple sections are going to be instantiated/destroyed)?
3: Can I use the default unity cylinder object for this (can I see the inside of that)?
A more efficient method of a scrolling tube is to scroll the texture UV values - a search on the forums/wiki for “uv scroll” should get you a handy script for that. That’ll also take care of your gap problem.
You can’t use the default Unity cylinder, no. It takes only a few button presses in Blender to create an inverted tube, though, which you can then easily import into Unity and scale to need.
The obstacles would then be moved according to the UV speed (which can be determined mathematically fairly simply), and you could move them far in front of the player rather than destroying them and instantiating them over and over (which can get expensive).
If that’s unacceptable, you’d just create a series of cylinders that are “X” deep, and “X” far apart from each other -
for ( var x : int = 0; x < numCylinders; x++ ) {
var c = Instantiate( cylinder, Vector3(0, 0, x * cylinderDepth), Quaternion.identity );
// calculate where the obstacle goes on the circle and its rotation based on that, then:
var o = Instantiate( obstacle, Vector3(0,0,x*cylinderDepth) + circleoffset, circlerotation );
o.transform.parent = c.transform;
}
Then each Update, the cylinders advance some amount towards the player (-Z in my example). If they’re past the camera, move them back out to the far distance (numCylinders * cylinderDepth-cylinderDepth), maybe rotate them randomly to not be a constant pattern.
So I could use this to achieve the scrolling tunnel illusion? Also, Im still not totally clear on the obstacles. I want to have random placement, so how do you instantiate things in a circle using the correct rotation (so, for example, if one obstacle shoots a burst of fire, how would I make it so the no matter where on the cylinder, the fire is always bursting towards the center)?