I’m making an tank-heavy game and one of the mechanics is for the player to be able to button up the hatch. I’d rather not model specific tank interiors since I plan on having more than 1 playable tank so I was thinking of using the periscopes in a similar manner to M1 Tank Platoon 2.

Periscopes!

It probably isn’t that obvious in the picture, but it is a 2D Texture that wraps around the camera. The overlay maintains a rotation that is relative to the turret and not the viewport. This lets the player look 360 degrees without encountering the end of the overlay, essentially forming the inside of a cylinder.

So, my question is: How would one implement this cylindrically scrolling overlay that rotates relative to a gameObject (the turret). I am already able to stitch full-screen GUITextures together, but I haven’t yet been able to make them wrap around the camera nor rotate relative to the turret.

I use MouseLook.cs to rotate the camera.

UPDATE: Okay, maybe my explanation above was a bit too confusing.

There’s a periscope at every 45th degree for a total of 8 periscopes. Each periscope is actually a separate GUITexture that is a child of a GameObject that moves along the X-axis in relation to mouseInput.

Supposedly this should give the player 360 degree vision, but as you can see, the overlay simply ends when going past 360 degrees. How would I be able to attach both ends of the GUITextures together so that it never ends (barring stitching on a carpload of GUITextures)?

Haha, okay. So I finally got past this little hurdle.

Instead of using a GUITexture, I used a childed quad placed 0.1 units in front of my camera. The quad had a Text Shader material containing the overlay. Then, I use this nifty piece of code I found on another answer…

var v3ViewPort : Vector3 = new Vector3(0,0,quad.localPosition.z);
	var v3BottomLeft : Vector3 = Camera.main.ViewportToWorldPoint(v3ViewPort);
	v3ViewPort.Set(1,1,quad.localPosition.z);
	var v3TopRight : Vector3 = Camera.main.ViewportToWorldPoint(v3ViewPort);
	quad.localScale = new Vector3(v3BottomLeft.x-v3TopRight.x,v3BottomLeft.y-v3TopRight.y,quad.localPosition.z);

…in order to make the quad fit the Camera’s aspect ratio. This is called at Start. Then used this…

quad.renderer.material.mainTextureOffset = Vector2(-Camera.main.GetComponent(MouseLook).rotationX/45,-Camera.main.GetComponent(MouseLook).rotationY/45);

to rotate it. The “45” part governs how many times the texture repeats in 360 degrees, ie. each texture is 45 degrees, making it repeat 8 times in a 360 degree turn. Same goes for the Y-axis.

Here’s how it looks in game:

https://dl.dropboxusercontent.com/u/282973338/WebBuild/WebBuild.html

Just press 3 on the keyboard to close the hatch. Other positions are still heavily WIP (can’t fire MG, etc).