Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Unity Noob · Aug 16, 2010 at 03:04 PM · zoomsniper

how do you zoom with a sniper?

when zooming with a sniper how do you make the screen black appart from a texture of a scope in the middle?

help is very much appreciated!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Aubrey Hesselgren · Aug 16, 2010 at 03:17 PM

http://unity3d.com/support/documentation/Components/class-GuiTexture.html Should help with how to display a full screen texture, as suggested by Andre.

In project view, find "Standard Assets\Blob-Shadow\Shadow" (assuming you included standard assets in your project). Highlight it by clicking on it.

Now click GameObject->Create Other->GUI Texture

If you hit play right now, you'll see a white square with a fuzzy transparent center. This is the wrong size and color, though, so...

Choose Blob Shadow in the Hierarchy view (i.e. the instantialized component in your scene). Rename it to something better (F2 -> "SniperScopeFuzzyOutline")

Now look at it in the Inspector so that you can edit the actual GUITexture component.

In the GUITexture component, select the colour. Turn it to RGB black, but Alpha 255. This will multiply the white texture by zero, which results in a black outline.

Now to change the size - move the X and Y (top left) co-ordinates to (-800, -800). Make the width and height double that (1600,1600) so that the center of the texture falls in the center of your screen (which I assume you'll use to cast your bullets out of - though some FPSs like Halo bucks this trend).

Hit play.

Tweak until you're happy. Change the texture that the GUITexture points to with your own if you want to adjust how quickly the edges get fuzzy - this is just a quick way to get a basic view set up for you.

Repeat the process with your own imported texture for the crosshair (which you might want to keep separate from the fuzzy scope for other reasons).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by Andre-Odendaal · Aug 16, 2010 at 03:11 PM

My suggestion would be to use a texture over the screen giving you the crosshair and blacked out scope view. Also make sure to narrow the field of view on your camera so that the player also gets a distorted view of the world.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Aubrey Hesselgren · Aug 16, 2010 at 04:08 PM

For the FOV change, you need to access the camera component's Field Of View value.

Let's set up an input to control it, first:

Go to Edit->Project Settings->Input

This opens the Input Manager

Change the "Size" value to 1 plus whatever it is. This will create an empty input for us to use. It will appear at the bottom with the same name as the last thing in the list. Change this name (the first option when you drop down) to "Zoom".

Click in the "positive button" field, then press the button you want to press in order to press this. I'm going to use "mouse 1" for now (which is the right mouse button... LMB is "mouse 0"). Later I'll add a joystick axis so that left trigger works with it as well. Except then I have to deal with the fact that Microsoft's xbox drivers are intentionally junk, and tie both triggers to one axis. Ahargh. Anyway. That can be fixed quite easily with XInput extensions, so it's no biggy.

Carrying on...

Make the "Type" a "Key or Mouse Button". Ignore the "axis" one, as it won't be used if you've got "Key or Mouse Button" selected. Equally, "Joy Num" doesn't matter for this input. It's the RMB after all.

We're going to do a neat trick here, which involves treating the Zoom button as if it's an axis, rather than just a digital input. This is to fake the "Easing in" and "easing out" of the FOV, so that we don't just snap the gun into ironsight immediately. Unity can fake this really well. Normally, to treat a button like it's digital, you set the Sensitivity (the "ease in" speed) to like, 1000, and the gravity (the "ease out") to the same. A good interactive rate (so that we don't transition for too long that it starts to feel sluggish) is typically less than 250ms. I like to keep it a bit tighter, so I want it to take 200ms to ease in and out. 200ms = 1second / 5. So I'm going to set my Gravity and Sensitivity values to 5 each. In 200ms, I will ease in and out. And if I release half into the ease in, it'll return back to zero from the point I stopped pressing. Responsiveness ftw!

We set up an an input to feed our behaviour from. Now let's gain access to the camera's field of view.

In your project, find a nice place to create a "CameraZoomButton" script component. I'm going to make a c# one because I am used to that (Right Click->Create->C Sharp Script). You might prefer java. Good for you.

Rename "NewBehaviourScript" to "CameraZoomButton"

Double click on it to edit it.

Here's what I've written up with inline comments.

using UnityEngine; using System.Collections;

//Note, class name must be the same as the file name. In Java, this is sorted naturally. public class CameraZoomButton : MonoBehaviour {

 //These values will be exposed to the component so that you can tweak them in real time. Joy!
 public float NormalFOV = 90.0f;
 public float ZoomedFOV = 45.0f;

 //Update is called once per frame
 void Update () {
     Camera CamComponent = GetComponent<Camera>();//We're going to need to grab the camera component associated with this object. See what that entails for the final step, here.

     //Check that we actually found a camera component
     if (CamComponent != null)
     {
         //If we made it here, we found a camera component! Awesome!
         float zoomInput = Input.GetAxis("Zoom");//Here's how we grab the current value of the input we created.

         //Just in case something whacky goes on with the axis, we clamp zoomInput to the range 0..1
         zoomInput = Mathf.Clamp01(zoomInput);

         //Optional: Here you could mess with curving the zoomInput a bit. It currently moves very straight from 0..1. Sometimes a straight linear interpolation can look "robotic".
         //Add "zoomInput = Mathf.Pow(zoomInput, 0.5f);", for a decceleration curve, for example. 

         //Use zoomInput to control a linear interpolation between our target zooms.
         //This "blends" finalZoom between the normal fov, and zoomed fov, using "zoomInput" (which we know is in the range 0..1) as the blending factor - kind of a "slider" between extremes.
         float finalZoom = Mathf.Lerp(NormalFOV, ZoomedFOV, zoomInput);

         //Make the camera use our final zoom
         CamComponent.fov = finalZoom;
     }
     else {
         //Warn ourselfs that we gone done it wrong.
         Debug.LogError("Camera Component not found. Did you add this component to a camera?");
     }

 }

}

Final step: add this component to your camera in your scene.

Select your main camera, then click "Component->Scripts->Camera Zoom Button"

Hit play. Zooming should work!

Next, I'll see how you control the GUI's opacity.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Aubrey Hesselgren · Aug 16, 2010 at 04:25 PM

First off, just for the sake of clarity in my project, I'm going to make the SniperFuzzyOutline game object part and parcel of my camera.

Then I'm going to add another little script, very similar to the last one, which changes the opacity of the gui texture involved in pretty much the same way as the FOV zoom. Copy pasta time!

Add another c sharp script called "CameraZoomOpacity". This is going to be very similar to the process of the last one, but we'll put the script on the SniperFuzzyOutline, and access its GUITexture component.

using UnityEngine; using System.Collections;

public class CameraZoomOpacity : MonoBehaviour {

 public Color unZoomedColor = new Color(0.0f,0.0f,0.0f,0.0f);//Color when unpressed
 public Color ZoomedColor = new Color(0.0f,0.0f,0.0f,1.0f);//Color when pressed

 //Update is called once per frame
 void Update () {

     GUITexture FuzzyZoomTexture = GetComponent<GUITexture>();//This grabs just the first texture in this component.
         if( FuzzyZoomTexture != null ){

         //If we made it here, we found a GUITexture component! Awesome!
         float zoomInput = Input.GetAxis("Zoom");//Here's how we grab the current value of the input we created.

         //Just in case something wacky goes on with the axis, we clamp zoomInput to the range 0..1
         zoomInput = Mathf.Clamp01(zoomInput);
         Color finalColor = Color.Lerp(unZoomedColor, ZoomedColor, zoomInput);//I love lerping colours! We blend between colours just like we blend between

         //Make the camera use our final zoom
         FuzzyZoomTexture.color = finalColor;
     } else {
         //No texture component found. Warn us.
         Debug.LogError("Please hook up the CameraZoomOpacity script to a game object which has a GUITexture component");
     }
 }

}

Add this script to the ZoomGui component!

Some of this stuff could probably be organized slightly nicer, but I am learning this as I answer your question.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Aug 16, 2010 at 11:14 PM 0
Share

$$anonymous$$y, you just wrote a tutorial for his project! :o)

avatar image Aubrey Hesselgren · Aug 18, 2010 at 10:50 AM 0
Share

I didn't know thing one about GUITextures before writing. It helps me learn! But there's a great danger of the blind leading the blind here, :)

avatar image
0

Answer by mediajolt · Feb 27, 2012 at 11:32 PM

This is really freaking cool, and so simple! Thanks for doing this!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

FPS sniper zoom effect without black texture? 3 Answers

Sniper scope zoom variances 0 Answers

How to add sniper zoom effect in an FPS made with Unity3d? 2 Answers

Sniper Zooming 2 Answers

Sniper Scope with zoom 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges