- Home /
FPS sniper zoom effect without black texture?
Hey guys I've been looking through the answers and really couldn't find the answer to this one.
1) should I bother animating an aiming animation (bring gun to centre of the screen) or should I just hard code it? (if it's better to code could someone point me in the right direction to start?)
2) How would I go about when the player right clicks they get a zoom effect (sniper zoom). Like in CoD but without the black texture around the screen so that they can see what's going on in the battlefield on the outskirts of the scope?
Sorry if it seems like I need spoon feeding but I would really LOVE some help with this! thanks guys!
I think that is rather question for forum as you are asking about opinions rather than facts.
Ad.1. One can say: code and another will write you: animate. We don't know how complicated/cool your project is and should be. Is it FPS? I guessed but you not wrote it here. We can be guessing but we don't even know is it the same game in the first and in the second question.
Ad.2. For me you should script some "scope camera" which will take over control over your "main camera" when onclick/ontouch (we don't know how it is controlled (IOS/PC/ANDROID/XBOX). You can do it with or without texture though I thought that it's hard to scope with both eyes open...
thanks for the input, forgot about those....... Target OS: Windows Genre: FPS, modern day shooter can anyone else help?
Answer by aldonaletto · Apr 27, 2012 at 12:43 PM
Animation can produce more natural and realistic results, but the hard code way may be good enough since aiming is a very simple movement.
A possible hard code way is to place an empty object at the aim position/orientation and child it to the camera. When aiming, Lerp the position and Slerp the rotation to the aiming object, and do the inverse path when returning to the standard position. To zoom in, just change the camera's Field Of View: narrow angles zoom in, while wider angles zoom out - like this (weapon script):
var aimObj: Transform; // drag the aiming position game object here var duration: float = 0.6; // animation duration in seconds var zoomFov: float = 25; // set the zoomed field of view
private var regPos: Vector3; private var regRot: Quaternion; private var regFov: float = 60; // standard field of view
function Start(){ // save regular position, rotation and fov: regPos = transform.localPosition; regRot = transform.localRotation; regFov = Camera.main.fieldOfView; }
private var aimInUse = false;
function Aiming(onOff: boolean){ if (aimInUse) return; // avoid multiple Aiming calls aimInUse = true; // signal that Aiming is running var t: float = 0; while (t < 1){ t += Time.deltaTime / duration; var r = onOff? t : 1-t; // r goes 0->1 or 1->0, depending on onOff transform.localPosition = Vector3.Lerp(regPos, aimObj.localPosition, r); transform.localRotation = Quaternion.Slerp(regRot, aimObj.localRotation, r); yield; // resume next frame } if (onOff){ // change the field of view after animation Camera.main.fieldOfView = zoomFov; } else { Camera.main.fieldOfView = regFov; } aimInUse = false; }
Call Aiming(true) to aim and zoom, and Aiming(false) to return to standard position.
thanks that awesome! How would I use that in conjunction with two cameras, I'm not sure how to model a proper scope with my model, so how can I use this with two cameras? (if that's the best way to do it)
A more sophisticated sniper scope would require Unity Pro: you should have the scope camera childed to the weapon and drawing to a Render Texture mapped to the scope visor - this way the image seen by the scope camera would appear only in the scope visor, and you could animate the weapon.
Without Unity Pro, you have two alternatives:
1- the code above, which brings the weapon to the aim position and zooms in the whole screen - only one camera is used;
2- a two camera approach, where the zoomed image appear in the scope and the rest of the screen remain the same. The trick here is to define a square viewport for the scope camera in the middle of the screen, and use a scope image to hide the viewport corners. There's a problem, however: you can't do the ai$$anonymous$$g animation because the scope viewport can't follow the scope visor - the sniper vision becomes thus an on/off thing: when pressing the ai$$anonymous$$g button, the scope immediately appears in the center of the screen, and just disappears when you release the button. You can see a complete sniper zoom script in this question: http://answers.unity3d.com/questions/177583/sniper-zoom.html#answer-177604
Thankyou for the response, This is a problem. I guess I'll just have to deal witht his one, unless I can set a timer, thanks! this is really helpful!
Answer by McDardy · Apr 27, 2012 at 11:56 AM
Ad.2. Add camera. I don't how you've got weapons but I can guess that riffle is different prefab. So add script and in it add function scope to it. In that function you can use the Unity function called GetMouseButtonDown(0). 0 is for the left button, 1 is for the right button and 2 is for the middle button. There's a corresponding GetMouseButtonUp(0), as well as GetMouseButton(0), which returns true every frame as long as the mouse button is down.
that function should change camera from your main to scope (or if you want no black texture) you should put that second, round scope camera on your main (cause it will be looking stupid zooming outside the scope).
So you should have two cameras and as long as right button is pressed you should be able to scope stuff - but that's only my idea ;)
When you'll have that you can also add rocket launcher with camera on bullets - that could be fun especially in not so realistic shooter.
Ad.1. I'd go with animation - it'll definitely looks better. But as I wrote in my comment one can say: code and another will write you: animate.
Answer by ExTheSea · Apr 27, 2012 at 01:39 PM
2: If you have a "scope" on the model you could use this one too if you want to. You just had to bring the gun in front of the camera and the lerp the Field of view of the camera down to what zoom you want. It maybe looks a bit jerky when you do it because you need a scope on the model which looks good and is big enough. You could also decrease the mouse intensity when zoomed in.
Just to give you an alternative without another camera but the answers above this one work too.
Your answer
Follow this Question
Related Questions
Could anyone help me with this weapon script? 1 Answer
Sniper zoom when right click? 1 Answer
Sniper Scope? 1 Answer
How to add sniper zoom effect in an FPS made with Unity3d? 2 Answers
Animation/CrossFade difficulties, Animation won't CrossFade 0 Answers