Sniper Scope Effect

Hi, all! I’d like to make a sniper scope effect where the area just around the visible part is bent refracted. Like, there is a visible part with lines and such inside the circle. The border of the circle (edge of the glass) refracts stretches the area it covers. Around that border is just black.
How would I code this?

A picture of an example would be helpful…

I guess any of these would work as a substitute, for I could not find any good examples of my desired effect online.

This one is the closest to what I want:

Those are Depth of Field Blur Effect. It’s only in Unity Pro.

http://unity3d.com/support/documentation/Components/script-DepthOfFieldEffect.html

In Indie I doubt there is anything that will work similarly.

Oh… Poop…
Well…
I have a sniper scope image… How would I make it so that once a certain value for the camera’s field of view is reached, the default reticle is switched out replaced with my scope image vice versa?

You could use another cam, so this cam is away from the player and it’s activate when you set the snipper. And the put the cam adquisition to a texture

I don’t think that would work as a good conventional zoom, though. Because at some points the further camera may be in the middle of a mountain or another mesh or may be past the level boundaries. In a zoom, the camera does not go through things, but enlarges them.

So how would I change GUI textures once a value of the zoom has been reached?

there is zoom effects which can be enabled and disabled on keyinput

in the unifycommunity.com - unifycommunity Resources and Information. it has the code required for zoom but you still would have the problem of zooming into the middle of the mountain, but you could have a look at the third person camera scripts which have solution to this problem

hmm… So you are saying that I should use a camera a certain length away from the camera, and it checks with a raycaster to see if there are objects in front of it, if there is, it goes up to that object?

Wouldn’t it be possible to get a somewhat similar effect by using a “dirty” texture on top of the sniper camera and alpha out the “zoom” target?

You could use a dirty texture or a scope texture.

For a zoom you want to change camera FOV, not move the camera.

Yes, but when you change the FOV:

  1. The mouse becomes waaayyyy too sensitive on mouselook

  2. There isn’t a way to switch out the gui texture

If you could tell me how to fix/achieve these things, you’d be my best friend. :slight_smile:

If you use the same camera and just change FOV:

multiply down the mouse deltas in your mouselook when zoomed.

Sure there is. Either switch activations on and off or point it to use the right texture.

How do you do each of these; can you please go into a little more detail for me?

:smile:

If you check in your mouse look script, there is probably a public variable called sensitivity or something similar. Changing this number results in a more or less sensitive mouse. Have you Zooming script change this number. If there isn’t such a variable, you can make one and multiply it in the rotation code of the mouselook script.

GUITexture.enabled should turn on and off the display of the texture. I actually haven’t checked this; but if that doesn;t work I’m sure there are other simple ways of making it work.

So you are saying that I should make the sensitivity a static variable?

You could, or you could have your Zoom script Find your mouseLook script and change the var that way. Either works.

Ugh. I am having trouble switching out the gui textures :rage:

var reticle : Transform;
var scope : Transform;
static var zoom : float = 60.0;
private var zoomed : boolean = false;
function Awake(){
	var crosshair = Instantiate(reticle);
}

function Update (crosshair) {
	if(Input.GetAxis("Zoom") == 1  zoom > 2.00){
		zoom = zoom - 1;
			}
	if(Input.GetAxis("Zoom") == -1  zoom < 50.00){
		zoom = zoom + 1;
	}
	camera.fieldOfView = zoom;


	if(zoom < 30){
		if(crosshair){
			Destroy(crosshair);
			snipe = Instantiate(scope);
			zoomed = true;
		}
		else{
			snipe = Instantiate(scope);
		}
	}
	

	}	
	
	if(zoom > 30){
		if(zoomed == true){
			Destroy(snipe);
			crosshair = Instantiate(reticle);
		}
		else{
			crosshair = Instantiate(reticle);
		
		
	}

}

The script does not know what the variable ‘snipe’ is, but that’s because it hasn’t been assigned yet! If the game would run, the variable would be defined and all would be dandy, but the game WON’T run ‘‘until all compiler errors are fixed’’.

Is there a workaround for this?

You don’t need a workaround, you just need to declare the variable somewhere. Where is up to you and how you want to use it.
Or, if you don’t need to store the scope instance, don’t put it in a var.