"Unity" 4.7 camera

Source: Internet
Author: User
Tags in degrees truncated

Categories: Unity, C #, VS2015

Date Created: 2016-04-11 I. INTRODUCTION

A camera is a device that captures and displays the world for the player. You need at least one camera in your scene, or you can use multiple cameras in one scene. These cameras can be set to render anywhere on the screen or in any order, in only some parts.

To present the game to the player, the camera is essential. You can customize, script, or parent a camera to achieve any effect you can think of. In jigsaw puzzles, you can keep the camera in a static state to see the full view of the puzzle. In the first person shooter, the camera can be parented to the player character and placed in a position with the character's eyes. In a racing game, you may want to have the camera follow the player's vehicle.

There are two types of cameras:

Perspective: Perspective camera. The camera renders the object in a completely perspective way.

Orthographic: Orthogonal camera. The camera will render the object evenly with a non-perspective rendering method. Ii. Import camera components from Unity

Right-click the assets in the drawing view and import the cameras component that comes with unity:

You can now see the imported four presets (prefabs) under the standard Assets folder:

The simple way to use these presets is simply to select a preset, drag and drop it into the scene, and set the camera's target area to root.

1. Imported Camera Type

The following is a brief introduction to the categories and uses of the imported cameras.

(1) Freelookcamerarig, Multipurposecamerarig

For both Freelookcamerarig and Multipurposecamerarig, "rig" is designed to follow objects that are always positioned toward the target. The camera offset is specified jointly by the "Pivot" value of the height (Y-axis) and the forward offset value of the camera.

L Freelookcamerarig: This camera can automatically follow the target position (where the mouse points to, where the target will follow), but also by moving the mouse (or touch gestures) to rotate a certain angle.

L Multipurposecamerarig: In addition to being able to follow the target position, the camera can turn around and then move to the target position you specify, which is very useful in multiplayer games.

The typical settings for both camera y-axis pivot (pivot) are 2 (2 meters above the target), and the typical setting for the z-axis pivot is-6 (6 meters behind the target).

If you want to adjust the camera to one side of the target (for example, to "turn" the 3rd person, i.e. the person or gun is turning around in place for the target), adjust the pivot value of the x-axis.

Camera Rig: Moves toward the target.

Pivot: Adjusts the height (the offset of the y-axis relative to the x-axis).

Camera: Adjusts the z-axis position of the distance target.

Both cameras use scripts from the ProtectCameraFromWallClip.cs file in order to prevent the camera from traversing past in certain items in the scene, such as walls or cars. Or, when it encounters an obstacle, it automatically goes around the past instead of directly through the wall.

In the Protectcamerafromwallclip script, the distance between the pivot and the camera is constantly checked, and when the camera is about to hit an obstacle, try to where it should be. For this reason, if you are using the wall clip (wall clipping) script, you cannot modify the camera offset during the run because the script will protect it from being modified.

(2) Cctvcamera

This camera is a Gameobject object without a hierarchy, in other words, it will only turn around and not move. Therefore, the camera does not require a wall clipping script. However, its target is still the object tag labeled "Player".

Cctvcamera uses the Lookattarget script, which also provides basic functionality outside of the Transform.lookat () function. It is relative to the local space of the target object's parent object and is constrained by its observed angle

The purpose of this camera is typically to present a scene from a moving car side window, aim a target from a mobile spaceship, and target a turret 、...... such as

The Cctvcamera can be placed anywhere, and can also be translated to achieve the target.

(3) Handholdcamera

Hand-held cameras.

2. How to use the camera components

By dragging and dropping a camera preset into the scene and setting the camera's target area to root, it automatically targets the first object labeled "Player" by default. In other words, you just have to set the tag tag of the target to "Player".

When you drag and drop a camera into a scene, the "Main camera" that is added automatically when you create a new scene is useless, and you can delete it directly. Third, related attributes

Camera is the most important component, and the target observed in the scene is controlled by one or more camera. Therefore, you must understand the various properties and meanings of camera, otherwise you can see nothing.

1. Clear Flags

Clears the tag. Determine which parts of the screen you want to clear. This property is handy when drawing different game elements with multiple camera. Available options are:

(1) Skybox

Sky Box. This is the default setting. All blank sections on the screen will display the Sky box for the current camera. If the current camera does not have a sky box set, it defaults to the Sky box selected in the Render settings (edit) and render settings (render Settings)).

(2) Solid Color

Solid color. Select this mode and the blank portion of the screen will display the background (background) color of the current camera.

(3) Depth only

Depth only. This mode is used when the game object does not want to be cropped.

If you want to draw the player's gun without clipping it in the environment, you can set the camera setting for depth (Depth) to draw the environment, while another camera with a depth (Depth) of 1 is used to draw the weapon clear flag (clear flags) separately and set it to depth mode only (d Epth only). This will cause the environment image to always appear on the screen, but will discard all information about the position of each object in the three-dimensional space. After the gun is drawn, the opaque part will completely cover all the painted parts, no matter how close the gun is to the wall.

(4) Don ' t clear

Do not clear. This mode neither clears the color nor clears the depth cache. The result is that each frame is drawn on top of the next frame, creating a drag effect. Commonly used in games with custom shaders (shader).

2, Background

Background. The color that is applied to the remaining screen after all the elements in the line of sight are drawn and no sky boxes. Or, if all the elements in the lens are rendered complete without specifying skybox (Sky Box), apply the non-placed color to the blank space of the screen.

3. Culling Mask

Culling a mask is also called culling. That is, add or remove the object layer of the camera render.

Description: Assigns a layer to an object in the viewer (Inspector). It is usually better to place the user interface (Interface) on a different layer and render it self-rendering, while rendering the user interface layer with a separate camera.

(1) Spot layer. Attaching a flare layer component to the camera (cameras) causes the image to appear with a lens flare (Lens flares) effect. By default, the camera is already attached to the flare layer.

(2) GUI layer. You can enable two-dimensional GUI rendering by connecting the GUI layer component to the camera. After the GUI layer is connected to the camera, all GUI textures (GUI Texture) and GUI text (GUI texts) are rendered in the scene. The GUI layer does not affect Unitygui in any way. You can enable or disable rendering of the GUI in a single camera by clicking the check box in the GUI layer (Inspector) in the viewer.

Also, in order for the UI to appear above other camera views, you need to set the clear flags to depth mode (Depth only) and ensure that the depth of the UI camera (Depth) is higher than other cameras (camera ) in depth.

4, Projection

Projection mode. Toggles the camera's analog perspective function. Options are:

Perspective: Perspective. The camera renders the object in a completely perspective way.

Orthographic: Orthogonal. The camera will render the object evenly with a non-perspective rendering method.

Setting the camera to orthogonal (orthographic) Removes all perspective effects from the camera view. This is useful when making isometric or two-dimensional games.

Note: Fog is rendered evenly using the orthogonal camera mode, so you may not get the desired effect.

5. Size

Size. When you select orthogonal (orthographic), the size of the camera viewport is set.

6. Field of View

Vision. When you select Perspective (Perspective), the width of the camera view is measured in degrees along the Y-axis of the local coordinates.

This item is only used for perspective mode, which controls the camera's viewing angle width and the longitudinal angle dimensions.

7, Clipping Planes

The clipping plane. The distance the camera starts to render and stop rendering. Options are:

Near: Close to the point. The point closest to the camera that is about to be drawn.

Far: a little farther away. The point that will be drawn farthest from the camera.

The clipping plane also determines how accurate the depth cache is distributed on the scene. In general, in order to achieve higher accuracy, the near-plane should be moved as far as possible.

Note: The Near and far clipping plane and the plane of the camera's field of view determine the area is commonly known as the camera flat-head body (frustum). Unity ensures that objects that are completely outside the level of the truncated body are not displayed when the object is rendered. This is referred to as the flat-truncated head culling (Frustum culling). Regardless of whether occlusion culling (occlusion culling) is used in the game, a flat-head culling (Frustum culling) will occur.

For performance reasons, in some cases you may need to cull small objects early (for example, to make small stones and fragments invisible in a much shorter distance than a large building). To do this, you also need to place the small object in the isolation layer and set the culling distance for each layer with the Camera.layerculldistances script function.

8. Normalized View Port Rect

Normalize the viewport rectangle, or call the standard view rectangle. A four-value control of the camera's view will be drawn on the screen's position and size, which uses the screen coordinate system (coordinates) and the value is between 0~1. These four values are:

X: Draws the horizontal start position of the camera view.

Y: Draws the vertical starting position of the camera view.

W: Width. The width of the camera output to the screen.

H: Height. The height of the camera output to the screen.

The normalized viewport rectangle (normalized Viewport rectangles) is specifically used to define which part of the screen the current camera view is drawn on. You can place a map view in the lower-right corner of the screen, or a warhead view in the upper-left corner. With a single point of design, you can create some unique behaviors with the viewport rectangle (Viewport Rectangle).

Use the normalized viewport rectangle (normalized Viewport Rectangle) to easily create a two-person split-screen effect. After creating two cameras, change the H value of the two camera to 0.5, then set the Y value of player A to 0.5 and the Y value of Player B to 0. This way, the player's camera will be displayed upward from the middle of the screen, while Player B's camera will start at the bottom and stop in the middle of the screen.

is a two-person display effect created using the normalized viewport rectangle (normalized Viewport Rectangle):

9, Depth

Depth. The position of the camera in the drawing order. A camera with a larger value will be drawn on top of a camera with a smaller value.

10. Rendering Path

The render path. Defines what rendering method the camera uses. You should choose according to the game content and target platform/hardware, different rendering paths have different function and performance characteristics, these features and performance characteristics mainly affect the lighting (Lights) and Shadow (Shadows).

(1) Use Player Settings

Use the Player settings to select the render path used by the item. Alternatively, the camera will use any of the render paths (Rendering path) set in the player settings (player Settings).

(2) Vertex Lit

Vertex illumination. All objects rendered by the camera are rendered as objects of vertex illumination (vertex-lit).

(3) Forward

Forward rendering. All objects are rendered as one channel per material.

(4) Deferred Lighting

Time-lapse illumination (Unity Pro only). All objects are plotted without illumination once, and the depth, normals, and highlight intensity of the geometry are saved with a buffer of screen space, and the resulting buffer will be used to calculate the light and generate a new light information buffer; All the game objects will be rendered again, The contents of the light information buffer are also automatically superimposed during rendering.

11. Target Texture

The target texture for rendering (Unity Pro only). This item is used to output and render the camera view to the screen. A stock used to make navigation maps or picture-in-pictures and other effects.

This feature also allows you to place the camera view on a texture that can be applied to another object. This makes it easy to create a stadium's big screen, monitor cameras and reflections.

Is the rendering texture used to create a live live camera (render Texture):

12. HDR

High dynamic illumination rendering range. This item is used to enable the camera's high dynamic range rendering capability. Because the human eye is more sensitive to low light intensity, using high dynamic range rendering can make the scene more realistic, and the light changes will not be too abrupt.

"Unity" 4.7 camera

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.