Digispired II Unity 3d Lesson Plans Lesson 3: Experimenting With Basics of Project Setup Edit->Project Settings->

gamgutturalMobile - Wireless

Dec 10, 2013 (3 years and 4 months ago)

88 views

Digispired II

Unity 3d Lesson Plans

Lesson
3
:
Experimenting With Basics of
Project Setup


Choose
Edit
-
>Project Settings
-
>
and you notice several options under “Project Settings”. We
will briefly disc
uss each one of these options.

Input Manager


The

Input Manager

is where you define all the different input axes and game actions for your
project
.


To see the Input Manager choose:

Edit
-
>Project Settings
-
>Input
.

Properties

Axes

Contains all the defined input axes for the current
project:

Size

is the
number of different input axes in this
project,

Element 0, 1, ...

are the particular axes to
modify.

Name

The string that refers to the axis in the game launcher
and through scripting.

Descriptive Name

A detailed definition of the

Positive Button

function
that is displayed in the game launcher.

Descriptive Negative Name

A detailed definition of the

Negative Button

function
that is displayed in the game launcher.

Negative Button

The button that will send a negative value to the axis.

Positive
Button

The button that will send a positive value to the axis.

Alt Negative Button

The secondary button that will send a negative value to
the axis.

Alt Positive Button

The secondary button that will send a positive value to
the axis.

Gravity

How fast will the input recenter. Only used when
the

Type

is

key / mouse button
.

Dead

Any positive or negative values that are less than this
number will register as zero. Useful for joysticks.

Sensitivity

For keyboard input, a larger value will result i
n faster
response time. A lower value will be more smooth. For
Mouse delta the value will scale the actual mouse delta.

Snap

If enabled, the axis value will be immediately reset to
zero after it receives opposite inputs. Only used when
the

Type

is

key / m
ouse button
.

Invert

If enabled, the positive buttons will send negative values
to the axis, and vice versa.

Type

Use

Key / Mouse Button

for any kind of buttons,
Mouse Movement for mouse delta and
scrollwheels,

Joystick Axis

for analog joystick axes
and

W
indow Movement

for when the user shakes the
window.

Axis

Axis of input from the device (joystick, mouse,
gamepad, etc.)

Joy Num

Which joystick should be used. By default this is set to
retrieve the input from all joysticks. This is only used for
input ax
es and not buttons.

Tag Manager


The

Tag Manager

allows you to set up

Layers

and

Tags
. To see it choose

Edit
-
>Project
Settings
-
>Tags
.



Details


Layers can be used to cast rays, render, or apply lighting to certain groups of objects only. You
can choose
the Layer in the

Game Object inspector
.

More information about how to use Layers
can be found

here
, while Tags are covered

here
.

Tags are used to quickly find objects from scripts, utilizing the Tag name. When a new tag is
added, you can choose it from the

Game Object

tag popup.

NavMesh Layers


The primary task of the navigation system is finding the

optimal

path between two points in
navigation
-
space. In the simplest case,
the optimal path is the shortest path. However, in many
complex environments, some areas are harder to move thru than others. To model this, Unity
utilizes the concept of

cost

and the

optimal path

is defined as the path with the lowest cost. To
manage cost
s, Unity has the concept of

Navmesh Layers
. Each geometry marked up
as

Navmesh Static

will belong to a Navmesh Layer. During pathfinding, instead of comparing
lengths of potential path segments, the cost of each segment is evaluated. This is a done by
scal
ing the length of each segment by the cost of the navmesh layer for that particular segment.
Note that when all costs are set to 1, the optimal path is equivalent to the shortest path.

To define custom layers per project



Go to

Edit
-
>
Project Settings
-
>
Navmesh Layers





Go to one of the user layers, and set up name and cost

o

The name is what will be used everywhere in the scene for identifying the navmesh
layer

o

The cost indicates how difficult it is to traverse the NavMesh layer. 1 is default, 2.0
is

twice as difficult, 0.5 is half as difficult, etc.



There are 3 built
-
in layers

o

Default
-

specifies the cost for everything not otherwise specified

o

Not walkable
-

the cost is ignored

o

Jump
-

the cost of automatically generated off
-
mesh links

One good use ca
se for using Navmesh Layers is:



You have a road that pedestrians (NavmeshAgents) need to cross.



The pedestrian walkway in the middle is the preferred place for them to go



Set up a navmesh layer with high cost for most of the road, and a navmesh layer with
a low
cost for the pedestrian walkway.



This will cause agents to prefer paths that go thru the pedestrian walkway

Managing Audio

The

Audio Manager

allows you to tweak the maximum volume of all sounds playing in the
scene. To see it choose

Edit
-
>Project Se
ttings
-
>Audio
.



However do not adjust the setting here for now.

T
ime Manager



The
time manager

allows us to work with the time inside of the game. The speed at which the
game will progress is controlled here.

You can access the

Time Manager

by
selecting

Edit
-
>Project Settings
-
>Time

from the menu
bar.

Properties





Fixed
Timestep

A framerate
-
independent interval that dictates when physics calculations
and

FixedUpdate()

events are performed.

Maximum
Allowed
Timestep

A framerate
-
independent interval that caps the worst case scenario when
frame
-
rate is low. Physics calculations and
FixedUpdate()

events will not be
performed for longer time than specified.

Time
Scale

The speed at which time progress. Change this value to simulate b
ullet
-
time
effects. A value of 1 means real
-
time. A value of .5 means half speed; a value
of 2 is double speed.




Fixed Timestep


Fixed time stepping is very important for stable physics simulation. Not all computers are made
equal, and different
hardware configurations will run Unity games with varying performance.
Therefore, physics must be calculated independently of the game's frame rate. Physics
calculations like collision detection and Rigidbody movement are performed in discrete fixed
time s
teps that are not dependent on frame rate. This makes the simulation more consistent
across different computers or when changes in the frame rate occur. For example, the frame
rate can drop due to an appearance of many game onscreen, or because the user la
unched
another application in the background.

Here's how the fixed time step is calculated. Before every frame is drawn onscreen, Unity
advances the fixed time by fixed delta time and performs physics calculations until it reaches
the current time. This di
rectly correlates to the

Fixed Timestep

property. The smaller the value
of

Fixed Timestep
, the more frequently physics will be calculated. The number of Fixed
frames per second can be calculated by dividing 1 by

Fixed Timestep
. Therefore, 1 / 0.02 = 50
fixed frames per second and 1 / 0.05 = 20 fixed frames per second.

Simply put, a smaller fixed update value leads to more accurate physics simulation but is
heavier on the CPU.


Maximum Allowed Timestep

Fixed time stepping ensures stable physics simulatio
n. However it can cause negative impact on
performance if game is heavy on physics and is already running slow or occasionally dips to low
frame rate. Longer the frame takes to process
-

more fixed update steps will have to be executed
for the next frame.
This results in performance degradation. To prevent such scenario Unity iOS
introduced

Maximum Allowed Timestep

which ensures that physics calculations will not run
longer than specified threshold.

If frame takes longer to process than time specified in

Maximum Allowed Timestep
, then
physics will "pretend" that frame took only

Maximum Allowed Timestep

seconds. In other
words if frame rate drops below some threshold, then rigid bodies will slow down a bit allowing
CPU to catch up.

Maximum Allowed Timestep

affects both physics calculation and

FixedUpdate()

events.

Maximum Allowed Timestep

is specified in seconds as

Fixed Timestep
. Therefore setting 0.1
will make physics and

FixedUpdate()

events to slow down, if frame rate dips below 1 / 0.1 = 10
frames per s
econd.

Typical scenario

1.

Let's assume

Fixed Timestep

is 0.01, which means that physx, fixedUpdate and animations
should be processed every 10 ms.

2.

When your frame time is ~33 ms then fixed loop is executed 3 times per visual frame on
average.

3.

But frametime

isn't fixed constant and depends on many factors including your scene state,
OS background taks, etc.

4.

Because of 3. reasons frametime sometimes can reach 40
-
50 ms, which means that fixed step
loop will be executed 4
-
5 times.

5.

When your fixed timestep tasks

are pretty heavy then time spent on physx, fixedUpdates and
animations extend your frametime by another 10 ms, which means one more additional
iteration of all these fixed timestep tasks.

6.

In some unlucky cases process described in 5. could extend to 10 an
d more times of
processing fixed step loop.

7.

That's why

Maximum Allowed Timestep

was introduced, it is the method to limit how
much times physx, fixedUpdates and animations can be processed during single visual
frame. If you have

Maximum Allowed Timestep

se
t to 100 ms and your

Fixed Timestep

is
10 ms, then for fixed step tasks will be executed up to 10 times per visual frame. So
sometimes small performance hitch could trigger big performance hitch because of increased
fixed timestep iteration count. By decre
asing

Maximum Allowed Timestep

to 30 ms, you
are limiting max fixed step iteration count to 3 and this means that your physx, fixedUpdate
and animation won't blow your frametime up very much, but there is some negative effect of
this limiting. Your animati
ons and physics will slow down a bit when performance hitch
occurs.

Player Settings


Player Settings

is where you define various parameters for the final game that you will build in
Unity. Some of these values for example are used in the

Resolution Dialog

that launches when
you open a standalone game.

To see the Player Settings choose

Edit
-
>Project Settings
-
>Player

from the menu bar.


Physics Manager


The
Physics Manager

is where you define the default behaviors of your world.

You can access the

Physics
Manager

by selecting

Edit
-
>Project Settings
-
>Physics

from the
menu bar.


Properties



Gravity

The amount of gravity applied to all

Rigidbodies
. Usually gravity acts
only on the Y
-
axis (negative is down). Gravity is meters/(seconds^2).

Default
Material

The default

Physics Material

that will be used if none has been assigned
to an individual

Collider
.

Bounce
Threshold

Two colliding objects with a relative velocity below this value will not
bounce. This value also reduces jitter so it is not recommended t
o set it to
a very low value.

Sleep
Velocity

The default linear velocity, below which objects start going to sleep.


Sleep
Angular
Velocity

The default angular velocity, below which objects start going to sleep.

Max
Angular
Velocity

The default maximum
angular velocity permitted for any Rigidbodies.
The angular velocity of Rigidbodies is clamped to stay within

Max
Angular Velocity

to avoid numerical instability with quickly rotating
bodies. Because this may prevent intentional fast rotations on objects s
uch
as wheels, you can override this value for any Rigidbody by scripting
Rigidbody.maxAngularVelocity
.

Min
Penetration
For
Penalty

How deep in meters are two objects allowed to penetrate before the
collision solver pushes them apart. A higher value will
make objects
penetrate more but reduces jitter.

Solver
Iteration
Count

Determines how accurately joints and contacts are resolved. Usually a
value of 7 works very well for almost all situations.

Raycasts
Hit
Triggers

If enabled, any Raycast

that intersects with a Collider marked as a Trigger
will return a hit. If disabled, these intersections will not return a hit.

Layer
Collision
Matrix


Defines how the

layer
-
based collision

detection system will behave.




Quality Settings


Unity allows you to set the level of graphical quality it will attempt to render.
Q
uality comes at
the expense of framerate

and so it may be best not to aim for the highest quality on mobile
devices or older hardware since it will have a detrimental effect on gameplay. The

Quality
Settings

inspector (menu:

Edit
-
>Project Settings
-
>Quality
) is split into two main areas. At the
t
op, there is the following matrix:
-


Unity lets you assign a name to a given combination of quality options for easy reference. The
rows of the matrix let you choose which of the different platforms each quality level will apply
to. The Default row at the bottom of the matrix is not a quality

level in itself but rather sets the
default quality level used for each platform (a green checkbox in a column denotes the level
currently chosen for that platform). Unity comes with six quality levels pre
-
enabled but you can
add your own levels using the

button below the matrix. You can use the trashcan icon (the
rightmost column) to delete an unwanted quality level.

You can click on the name of a quality level to select it for editing, which is done in the panel
below the settings matrix:
-



The quality

options you can choose for a quality level are as follows:
-



Name

The name that will be used to refer to this quality level

Pixel Light
Count

The maximum number of pixel lights when Forward Rendering is used.

Texture
Quality

This lets you choose
whether to display textures at maximum resolution or at a
fraction of this (lower resolution has less processing overhead). The options
are

Full Res
,

Half Res
,

Quarter Res

and

Eighth Res
.

Anisotropic
This enables if and how anisotropic textures
will be used.

Textures

Disabled

Anisotropic textures are not used.

Per Texture

Anisotropic rendering will be enabled separately for each Texture.

Forced On

Anisotropic textures are always used.

AntiAliasing

This sets the level of antialiasing that will be used.

The options
are

2x
,

4x

and

8x

multi
-
sampling.

Soft Particles

Should soft blending be used for particles?

Shadows

This determines which type of shadows should be used

Hard and
Soft Shadows

Both hard and soft shadows will be rendered.

Hard
Shadows
Only

Only hard shadows will be rendered.

Disable
Shadows

No shadows will be rendered.

Shadow
resolution

Shadows can be rendered at several different
resolutions:

Low
,

Medium
,

High

and

Very High
. The higher the resolution, the
greater the processing overhead.

Shadow
Projection

There are two different methods for projecting shadows from a directional
light.

Close Fit

renders higher resolution shadows but they can sometimes
wobble slightly if the camera moves.

Stable Fit

renders lower resolution shadows
but they

don't wobble with camera movements.

Shadow
Cascades

The number of shadow cascades can be set to zero, two or four. A higher number
of cascades gives better quality but at the expense of processing overhead (see the
Directional Shadows page for further de
tails).

Shadow
Distance

The maximum distance from camera at which shadows will be visible. Shadows
that fall beyond this distance will not be rendered.

Blend
Weights

The number of bones that can affect a given vertex during an animation. The
available
options are one, two or four bones.

VSync Count

Rendering can be synchronised with the refresh rate of the display device to
avoid "tearing" artifacts (see below). You can choose to synchronise with every
vertical blank (VBlank), every second vertical bla
nk or not to synchronise at all.

LOD Bias

LOD levels are chosen based on the onscreen size of an object. When the size is
between two LOD levels, the choice can be biased toward the less detailed or
more detailed of the two models available. This is set a
s a fraction from 0 to 1
-

the closer it is to zero, the more the bias is toward the less detailed model.

Maximum
LOD Level

The highest LOD that will be used by the game. Models which have a LOD
above this level will not be used and omitted from the build

(which will save
storage and memory space).


Network Manager


The

Network Manager

contains two very important properties for making Networked
multiplayer games.

You can access the Network Manager by selecting

Edit
-
>Project Settings
-
>Network

from the
menu

bar.



Properties





Debug Level

The level of messages that are printed to the console

Off

Only errors will be printed

Informational

Significant networking events will be printed

Full

All networking events will be printed

Sendrate

Number of times
per second that data is sent over the network





Script Execution Order Settings


By default, the Awake, OnEnable

and Update functions of different scripts are called in the
order the scripts are loaded (which is arbitrary). However, it is possible to modify this order
using the

Script Execution Order

settings.



Scripts can be added to the inspector using the Plus
"+" button and dragged to change their
relative order. Note that it is possible to drag a script either above or below the

Default
Time

bar; those above will execute ahead of the default time while those below will execute
after. The ordering of scripts in

the dialog from top to bottom determines their execution order.
All scripts not in the dialog execute in the default time slot in arbitrary order.