welcome to the physics playground
prototype a way to get started
experimenting with physics in unity this
video is part of our beginner prototype
series in which we explore creating
small products focused on game mechanics
we wanted to create a prototype that
allowed players to experiment with
unities physics system which allows you
to create a lot of complex gameplay with
a few simple elements in order to do
this we decided to create a camera that
can fly around the playground room and
allow the player to click with the left
Mouse to spawn objects and also use a
shift-click to destroy them we also
decided to make it possible in the
project to change gravity freeze the
physics of objects at any time go into
slow motion and more this allows players
to really experiment with a lot of the
crazy stuff that you can do with time
and physics in unity in a fun way
here's a quick overview of what we will
look at in this video the camera and how
we move and control it the object
spawning and the spawning system how
we're managing physics and our explosive
bomb objects in later videos we'll
explore the physics and gravity effects
and how we added effects and polish to
the prototype let's start by looking at
our camera we knew we wanted to have a
free-flying camera to allow players to
navigate the scene and place objects in
a flexible way the camera represents the
viewers perception of our scene setting
up a camera properly can be very complex
for this reason unity comes with a
powerful tool called cinema Sheen this
can be found in a package manager and
comes with different camera setups ready
to be used for example a cinema scene
free look camera is perfect for
third-person camera experiences it
orbits around three customizable rigs
given the possibility to explore and
move around the target using the mouse
without writing any additional code
in this product we wanted to move the
camera the way that you can move it in
the scene view of the unity editor in
the scene view there's possible to move
and rotate the cameras position by
holding down the right mouse button and
pressing the W a s and D Keys to achieve
this we use an empty city machine in
virtual camera and added our sample
camera controller script attached to it
this is based on a script which you can
find in the script folders of any new
empty unity project that uses one of
unities provided templates the cinema
scene virtual camera comes with many
possible extensions these extensions
provide useful additions to the camera's
behavior for example the cinema scene
confine ur limits the cameras position
to an area of our scene the cinema scene
in post listener generates and manages
camera shake reactant to game events we
decided to use both of these in our
prototype since we're using a
free-flying camera we chose to use a
combiner to prevent players from flying
the camera out of the play area we
decided to use the impulse listener to
shake the camera when explosions happen
this makes the explosions feel powerful
and a prototype feel more exciting we
wanted to create a system to allow
players to spawn and these pong objects
we decided to do this by allowing them
to spawn by clicking with the left mouse
and to de-spawn using shift-click we
first tried using right click but
realize that we needed the right click
to be used by the cameras movement and
so decided that shift-click would be a
good choice for the leading since it's
something players will do less often
this means that clicking with the left
mouse button instantiate Sanu object in
the scene to instantiate in this context
means to copy an object in our world
while the game is running you will also
hear people talking about spawning or
creating objects which means the same
thing
the idea for this prototype is for
players to have fun instantiating
objects wall physics is frozen and when
they're done doing that
turning the physics on to see what
happens when we instantiate an object
usually we do it based on something
called a prefab a prefab can be thought
of as a template for an object which has
been assembled previously and then saved
if you want to you can create complex
shapes by combining different 3d objects
into a single prefab for instance this
castle is composed of several prefabs
nested under a single parent game object
allowing us to spawn them all together
with one click with the keyboard keys V
and B we allow players to cycle through
the spawn of all objects while the game
is running to show the player what they
are about to place we position a ghost
object with a special outline material
in the world as a placeholder for where
their new object will be spawned when
they click while we were designing the
system we also added a line extending
down from the marker to show what it was
going to be placed on top of since
sometimes visualizing what something is
above in a 3d view it's not easy the
marker displays objects are instantiated
at the beginning of the game and then
turn up except the first visible object
when possible it's good to reuse game
objects instead of spawning new ones
this is because enabling or disabling
game objects is more efficient than
instantiate in a new copy every time we
design the spawner script to make it
easy to add new prefabs for the player
to spawn if you would like to add your
own new spawn of all objects you can
find the objects list in a spawner
script attached to the manager's game
object and you can drag your own prefabs
into it when adding new objects we want
to make sure that each prefab has a
rigidbody component and a Collider
component attached to it in order for it
to be affected by physics and used by
our manager scripts
we'll talk a bit more about what these
components do later in the video we also
added functionality to the spawner
script to allow players to delete or
destroy objects by holding down shift
and left clicking this allows them to
clear space or allow players to play
around with removing objects while
physics are turned on and seen if things
fall over in this prototype physics are
really at the heart of gameplay we want
our players to be able to go back and
forth between physics and no physics
mode in a way that was somewhat similar
to the way you go in and out of the play
mode in a unity editor with the space
button we can switch between physics on
and physics off modes these are
represented by the play and pause icons
in our in-game UI in the lower left hand
corner of the game view we realize while
we were working on the prototype that it
wasn't always clear what modes were on
or off and so we added a number of
features to try to make it as clear as
possible what state the game was in
including this UI in the physics on mode
objects are affected by physics this
happens because each object has a
rigidbody component attached to it this
component lets you nice physics engine
control the objects motion pulling it
downward with gravity and reacting to
collisions with other objects if a
Collider component is attached to each
of them the fun thing about making games
that use physics is that the physics
engine will handle off these
calculations for you making it an easy
type of gameplay to get started
designing when we play our scene and
activate physics on mode objects fall to
the ground collide with each other and
even react to explosions the physics off
mode is the opposite in this mode
objects are not affected by physics even
though they do have a rigidbody
component attached to them this is
possible thanks to the is kinematic
property of the rigidbody component if
is kinematic is enabled forces
collisions or joints will not affect the
rich body anymore in other words a
kinematic object remains still in the
position and it's not moved or rotated
by physics forces it does however
continue
to effect other objects that collide
with it due to its attached Collider
colliders are invisible elements that
enable physical collisions if you ever
run into an impassable invisible wall in
a video game you have encountered a
glider in most cases colliders match the
visual shape of an object's mesh the
mesh of an object is a 3d geometry which
allows it to be rendered on screen this
means that objects which have meshes but
not colliders and rigid bodies are like
ghosts we can see them but they don't
collide with other objects nor are they
affected by forces our placeholder
object that we are using as a marker to
decide where to spawn things doesn't
have a Collider or rigidbody and this
means that we can move it wherever we
want without affecting placed elements
the way that all of this is coming
together in our scene is that we are
using our spawn object manager script to
turn the is kinematic property of spawn
objects in our scene on and off when the
physics most changed because the player
press the button by default the spacebar
to make things more interesting we
created an explosive component attaching
this component on a spawn double object
makes it very dangerous on the first
collision with another element in the
scene the explosive object starts
blinking and after that it explodes
pushing away nearby objects this type of
bomb that explodes when it's touched
it's something that we seen in a number
of physics games and makes the gameplay
more interesting because it creates a
kind of chain reaction effect when
something falls on top of it or it falls
over the explosive component is
configurable and you can set many of its
properties like explosion power radius
and countdown time we will be continuing
to explore the physics playground
prototype in upcoming videos including a
video on how we set up the slow-motion
and reverse gravity effects in another
video on how we polish the prototype
including post-processing particles in
audio the physics playground is
available to download for free
via the link in the description if you
are interested in digging more deeply
into the concepts shown
we've also recorded a slightly longer
workshop video which is published on a
uni learn web
it you can find a link to that in the
description as well hopefully this has
given you some ideas for how to use some
of these tools and techniques in your
own games thanks for watching
[Music]