[Music]
hello everyone and welcome back to the
kia ora theater at linux conference
australia 2022
uh
our next presentation is pre-recorded uh
so
uh
i'm the only person talking to you right
now but we will get pre-recorder paris
in here soon
um
so dr paris buttfield addison is the
co-founder of independent game
development studio secret lab today he
is here to help us learn about godot
oh i didn't check how to pronounce godot
we'll learn in the talk uh take a
tour of its features and powerful
scripting system and quickly build a
game uh showcasing the godot editor for
mac os windows and linux
paris is available in chat throughout so
feel free to ask questions as we go take
it away with your pre-recorded paris
hi everyone welcome to let's make a game
my name is paris but for edison
you can tweet me at paris ba i'd love to
hear from you
please feel free to do that and let me
know what you think questions about godo
anything else or just want to tell me
you like my glasses which is a common
comment
i am a video game developer
uh best known for working at secret lab
which worked the night in the woods lots
of o'reilly books lots of technical
books uh and the younesman narrative
game tool
today i'm here to talk to you about a
fantastic and completely free and open
source game engine named gotto or godot
depending on how you pronounce these
things
godot is a fully open source project
that really genuinely competes with the
big mainstream commercial video game
engines like unreal and unity it is
named after the play with pictured here
starring patrick stewart and ian
mckellen that was a fantastic player uh
but starring many people over the years
it is a powerful little gaming engine uh
it is a project of the software freedom
conservancy uh the software very
conservatively shepherds a lot of
projects and godot is one of them they
make sure that the project is compliant
with their open source licenses and
other people are compliant with the
license when they're using them
but godo really is an astonishingly
powerful game engine it is one of my
favorite free and open source projects
it has many of the same features as the
big commercial projects uh and really
competes with them but it's entirely
free in open source it has good ui good
ux uh it's
quite easy to develop with it's powerful
it can deploy to almost every platform
you can think so uh today i'm going to
take you through building a little game
very simple game from scratch
and talk about how and why you can use
godo to do this sort of thing
hopefully by the end you'll see why it's
really powerful and how it's easy to use
i'm not going to
structure this tutorial this is more
just going to be
enthusing you about gotto so don't
necessarily try and follow along i
really hope you enjoy it's a really good
fun relatively cheap hobby to build
little video games share with your
family and friends uh
let's jump in and get started so
we'll see how it goes
here's gotto open on my uh my macos
device
godo runs on pretty much anything linux
macos windows
you can uh see it running in the dock
there it's got this cute little robot
icon
so
in godo
godo is actually written in godo so the
game engine itself that you're using to
write your game is actually built using
godo which is a pretty cool thing and
they're pretty cool proof that it's
actually a pretty solid thing
i'm going to click the new project
button to make a brand new project
well hopefully that works
and
and we're going to call it paris and
tim's game
because we designed this uh this game
together with tim nugent my colleague
for using in talks and tutorials
and i'm going to select opengl 3
and create an edit and it's going to
make a brand new project in gotto
and i'm just going to maximize godot
there
so this is gotto got it looks like most
3d tools in most game engines it has a a
3d environment for you to navigate in
and move around in it operates on three
different axes x y and z
and you can manipulate the scene using
those axes in the corner there so we're
not going to go into too much detail on
how to navigate in 3d hopefully many of
you have used blender or a similar 3d
tool but if you're not it's not too hard
my only recommendation would be if you
were using a laptop maybe plug in a
mouse if you're not super confident
using the trackpad to do this kind of
thing
so this is our big formless void that we
exist in here in godo
and we're going to turn this formless
void into a video game
to turn this formless void into a video
game uh
it's empty at the moment we're going to
add a node to this scene
uh our root node for the scene is kind
of going to dictate what kind of scene
it is so everything in godot is made up
of scenes with nodes in them
here are the options for the various
kinds of root nodes we can create
we're going to make it spatial
so a spatial node is a basic 3d parent
in gono so everything that is kind of 3d
descends from this spatial mode and
gallo spatula doesn't really do anything
beyond have a a transform
a space a thing that makes it exist in
the space in a certain position
so here is our spatial node it's
currently just called spatial it's very
unexciting
we can add additional nodes below this
spatial node as we desire and we'll be
doing a lot of that today
so
this is our spatial node here in the in
the node list in the node viewer
we're going to add another node
while our spatial node is selected
it's going to be a mesh
instance node
a mesh instance node references a mesh
and lets us have something visible in
the scene so it meshes any kind of 3d
object it could be a primitive 3d object
like a cube or it could be something
you've rendered in blender
so node is the parent of all things in
godo and then we're using spatial node
which is below it and then there's this
hierarchy of nodes which dictate how
things work so a mesh instance is
a child of spatial and spatial is a
child of node
so we've now got a smash instance as a
child of our spatial mode
we're going to make a cube so over here
in the inspector while our mesh instance
is selected over on the right side of
the screen
we're going to add an actual mesh so
we're going to click the empty mesh area
i'm going to go new cube mesh
uh if we wanted to we could import an
actual mesh from like blender or one of
the commercial modeling packages here if
we wanted to but uh goto like most game
engines ships with a bunch of primitive
uh you can use
so now is our lovely cube as you can see
that video game is basically done
we're going to go to the materials
section and go
new
spatial material
and we're going to set it to a color
because we want our video game to be
nice and colorful
so uh hmm what color should we make it
maybe yeah orangey
yeah this is a good color so this mesh
cube is going to be our floor for our
video game so our floor is going to be a
nice
egregious orangey brown
kind of color that looks pretty good
so we've got our nice orange cube
so
with our cube made we're going to select
the mesh instance over in our inspector
again
and we're going to click the little mesh
button in the top of the screen
this button
allows us to create a static body for
the mesh
so this body will allow the mesh to
collide with things in the world
currently it's just a picture of a cube
and by clicking this button we give it a
static body which allows it to collide
with things in the physics engine that
godo ships with
so
video games uh
often have really high resolution
complex meshes
uh so
you need to create a
fancy collision body to map to it
because you can't use the mesh itself as
the collision body for performance
reasons in older video games you'd often
use the mesh itself as the collider
these days you kind of want to make a
simplified mesh that goes around it to
serve as the collision body you
technically don't have to do that
because we're doing it with cubes we
could get away with just using the cube
as the collision body
but good practice in video game
development is to create a collision
shape that is a simplified version of
the thing you're actually using in this
case the simplified version will just be
another copy of a cube but uh using that
create mesh button means you're doing it
properly
so a static body in godot is a thing
that exists in the phoenix engine but
doesn't move or is at least strongly
discouraged from moving so there's a
different type of body with a collider
you would make if you wanted it to move
and you'll see that a bit later
so i'm going to select the mesh and push
the r button which switches to scaling
mode and you can see the different tools
we can use here so i push the r button
on the keyboard and i'm going to squish
the cube a little bit to make a floor
this is just changing the transform of
the cube
it doesn't mean i have to do anything
precisely uh i could just make a floor
basically so i could also use the
transform inspector to fiddle with it
here so i'm going to make it bigger 10
and i'm going to make it half high and
i'm going to make it 10 again
so now we've got a nice big flat floor
it's our orange
so most video game engines have kind of
settled on this approach where you have
objects with parameters attached to them
uh commercial alike unity unreal goto
game maker all of them have this kind of
component based architecture
that they use
to
give things behaviors and parameters so
you attach things to things and some of
those things have parameters in godo's
case you have nodes and you have
components attached to those which give
you properties
uh
yeah it's very common this is not just a
gun i think this is a generic game
development thing
i've just renamed the spatial mode to
floor
so i've right clicked on it and gone
rename and call it floor because it's a
floor
so our scene is currently unsaved
we need to save it so to save it i'm
going to push command s on mac or
control this on linux or windows
floor.tscn is good i'm going to just
save it so now we've got a floor scene
it's saved you'll see down here in the
file system inspector we have a copy of
that floor scene available to us now
that's everything for the floor
so
godo
actually
does something quite interesting and
many other game engines now inspired by
godown are doing as well uh goto builds
everything up out of scenes
so you can actually nest scenes within
each other and we'll see how that works
later on
uh you might have like a player scene
you might have multiple players scene
you could load multiple instances of one
scene to another scene so you kind of
use scenes as this basic object format
which you can then load into other
scenes so you can replicate things and
then only update the original
for
creating it
it's very useful uh godo and unity
really lean on this heavily so speaking
of scenes i'm going to make a new scene
right now with the scene menu and now
we'll end up with an empty scene you'll
see the flaw still is up there
i'm going to do pretty much exactly the
same thing as i did last time and add a
new spatial node
inside that spatial node i will add a
mesh instance
exactly the same as i did last time
inside the mesh instance i will create a
new mesh again another cube
and i will create another material and
set a different color on this mesh and
we'll have to have a think about which
column
maybe yellowy
yellow's good a bit too green there yeah
yellow yellowy
yellow is good that's disgusting yellow
love it
perfect
i'm going to create another tri-mesh
static body for our mesh because it's
also going to be static and i'm also
going to scale it a little bit by
modifying the transform i'm going to
make it uh
0.25
1 and 10. so this is going to be a nice
wall for us to use
so
you'll see we've made a little wall here
i'm going to rename the spatial node to
wall
walls
and i'm going to save that scene so it's
going to be called walls.tscn
now we've got two scenes open
we've made two fantastic scenes a floor
and a walls both egregious disgusting
colors i'm going to make yet another
scene now
and
i'm going to add a spatial node to that
scene
yep spatial node done
i'm going to rename the spatial node to
environment
this uh this scene is going to hold our
level
this is going to hold our world that the
player has adventures in
so i'm going to select the spatial node
and click the link node so the add node
lets you add new fresh nodes to the
scene and the link node lets you bring
in existing scenes so i'm going to click
that link button
and you'll see my two scenes already
saved before
i'm going to click the floor
so now we've linked the floor scene into
our new scene
so anything we modify in the original
floor scene will take effect in this
scene because they're linked
i'm going to now
do the same thing again so i'm going to
select the environment node so it's
going to be a child of the environment
and then i'm going to select walls
so now you'll see my walls are on top of
my floor well actually embedded in it
right now
i'm going to use the move tool w on the
keyboard and i'm going to move the walls
to be you know actual walls i'm going to
move them
over here it's not snapping very nicely
so i'm going to actually turn on snap by
selecting the snap button or pushing y
on my keyboard which will make it snap
you can configure the snap and how it
works so what parameters it snaps to
i'm going to switch the view to the top
so i can see it nicely to align my walls
now i can use snap to place the wall in
the right position
i'm going to select the walls and push
command d on my mac or control d on
linux or windows and duplicate my walls
again these are all linked copies of the
original wall scene so if i went to wall
scene and made it less egregious yellow
it would change all the copies of the
wall
i'm going to duplicate the wall again
so we've got three walls now this is
pretty common in most games you are
duplicate things move around in 3d space
duplicate things so on and so on so i
need to rotate it so with the wall i
need to rotate selected i'm going to go
to the transform inspector and going to
rotate it 90 degrees on the y axis
so it's flipped around exactly how we
need it then i'm going to move it
and duplicate it again
and put it down at the bottom so now we
have four walls on our scene
i could fiddle with the snapping a
little bit to make it more precise
but uh this is how you do that i haven't
got the energy to do that right now
you know so i can make it
0.5 on i guess i'm not as lazy as i
thought it was
so now i can snap a little bit better
nice nice and precise
it looks good how it was i'm gonna leave
it
now i'm gonna save this as
environment.tcn so command s or control
s and saving
now i've saved the scene we've got this
beautiful scene up and running
look at that it's beautiful our game is
almost done
so obviously i need to move the walls up
a little bit so i'll just slide them up
a little bit
they're not quite in the right position
i want them to be in so i'll move them
all up while the snap tool is still on
this one
and this one
that looks great
now they're much more wallish than they
used to be beautiful
so also hit command s to save it
beautiful floor it's great we're nearly
done we're not actually done no okay so
now i'm going to rename the floor to
lower floor
because we're going to have an upper
floor in a minute as well and we don't
want to get confused i can't put spaces
in and i am just used to not having
spaces in files
i'm going to link another instance of
floor
well oops no i'm going to link another
instance of the floor scene sorry
there we go i don't want to nest myself
in myself there so now i have two floors
they're exactly in the same place right
now so i'm going to move one of them up
a little bit and put it over here so we
have an upper floor and a lower floor
isn't that fantastic look at them
i'm going to rename it so it's upper
floor and i don't confuse myself
again you can have spaces i'm just old
school
so with our two floors in place
uh we can
move on
so
two floors what else do you think we
need well
we might need a uh
an additional
way to get between the two floors i'm
not going to put any walls on the upper
floor i'm actually going to make a brand
new scene again
and
repeat the process that we've done so
far add a spatial node uh you know add a
mesh instance
uh first i'm going to run this ramp
actually
now i'm going to add the mesh instance
and with my mesh instance i'm going to
create a
oops i didn't create a mesh i'm going to
create a mesh on this new mesh instance
so we actually have something
visible
so on our mesh instance i'm going to
select the mesh instance and then like a
second ago i'm going to create a new
cube mesh
and pick a new egregious color so maybe
like another green yellow egregious
i don't know maybe
ooh green yeah maybe nice and green that
looks good
okay
the green really screams ramp to me
so big ramp energy so i'm going to
create my static clutter again
and modify the transform of this mesh to
make it more ramp like
so maybe uh 1.44
0.1 and
5.47 yeah i think that's good that looks
like around to me i totally did not
prepare those numbers in advance
that's beautiful i'm going to save that
scene as ramp.tscn
done beautiful
back in our environment so i'll switch
the tab at the top there
i'm going to uh link in the ramp
so add the node via the link
button has a child of environment
so
we're going to select that link button
and we're going to choose ramp.tscn
and with the ramp in the scene you'll
see it's embedded in the floor currently
so we're going to move it up a little
bit
there it is it is our facing the wrong
way
but we'll fix it
in a moment
we control the universe so it doesn't
really matter where anything goes so
we'll hit the rotation button and then
we'll use the rotation button to rotate
it a little bit look at that that's
beautiful
rotated and then we'll move it across a
little bit using the move button
and rotate a little bit more so it
actually is a ramp
and we've got a ramp happening there
that's great
that's close enough that's kind of good
i think yeah it looks nice to me
i'm going to save that just so it's uh
preserved
we might clean that up a bit in the
future
but right now
our game is almost there but we're
missing one crucial thing a player
so i'm going to make a new scene
the scene is going to be our player
we could have put all of this in one
scene and made all these things out of
nodes but then it wouldn't be following
a nice reusable game architecture
because when you're building video games
it makes sense to make things out of
composable pieces so you can reuse them
as you need in a multiplayer game you
might have a player scene that is
instantiated multiple times and
connected to different inputs some over
the network for example
and by doing it like this even when
you're making a silly little sample game
uh it helps you keep things
reusable so we're going to create a
kinematic body
kinematic is a fancy word for it moves
so unlike our static body the kinematic
body can actually move around
so we need a mesh as well
so below our kinematic body
we're going to have a mesh it's not
going to be a cube this time we're going
to make a capsule because the
traditional prototyping
mesh for video game is a capsule
prototyping is always a capsule i'm
gonna pick a nice egregious color for
our player
maybe bluey blue yeah i think blue today
for our player
that that says player to me
nice blue player
cube we're not going to rotate it up uh
we'll rotate it up later
so we're going to click on mesh
uh click our kinematic body and click
collision shape
this allows us to
represent this in the physics engine
but this means it can move as well it's
not a static thing
our collision shape
must have a shape attached to it so with
our collision shape selected we need to
go over to the inspector on the right
and allocate a shape to it
so
our collision has a little error on it
that's because it doesn't have a shape
assigned to it so
in the inspector we're going to go
across
and give it a shape
and surprising nobody it's going to be a
capsule
so this is the uh the thing that's
actually represented in the physics
engine for this shape and coincidentally
it's also a capsule because the capsule
just needs a capsule collider
but unlike the other static stuff we
created because this is kinematic with a
collision shape it can move because it's
helpful when your player can move
with that done
we are going to save our scene and
continue
uh player collision bodies in video
games actually often
cube capsules even if the player is some
sort of complex thing just because it
makes it easier to calculate what's
going on with the environment and keep
keep things simple
big fancy games obviously do other
things but simple video games are often
just capsules so we're going to save our
player scene there
and rename the kinematic body to player
and then save it again
that's it for the player scene so we'll
go back to the environment scene and i
bet you can guess what we're going to do
we're going to link the player scene as
a child of environment
now our little tic-tac-man is in here
man woman tic-tac creature not sure why
a tic-tac has a gender it doesn't need
one uh
it's a tic tac
so
it's a it's a it's a little capsule
player i guess it does not have a gender
you will uh you really really end up
loving your your terrible shapes you use
so don't get too attached to them
we're going to rotate so click that
player without it and rotate it so it's
pointing the right way and then use the
move tool to move it up
it doesn't matter that it's above the
ground because we're going to add
gravity
so for now it can just sit there
floating
that's totally fine
so
we're going to make yet another new
scene
we're going to go scene new scene this
scene is very simple
so we're going to create a rigid body
which allows it to move in the physics
system
this is a little bit different because
it needs to move around the scene in a
different way so we'll cover that in a
second we're going to add a mesh
instance to our rigid body
on our mesh we'll add a sphere
and make an egregious color probably red
i think this time
nice egregious red
we'll add a collision shape
because we want this to be able to
collide because it can move
so we'll click our collision shape and
add a sphere
as the shape in the inspector
it's a rigid body that can move in the
physics engine which can move using
impulses it has a mesh instance to show
it's a ball
and it has a collision shape which is
also a ball or sphere and we'll save it
as ball so ball.tscn and we'll rename
the route to ball
so it's just a ball we're going to save
our ball scene back in the environment
you'll know where this is going we're
going to click environment and link the
ball scene in
and then we have a ball
we're going to move the ball up to the
upper platform
so
the center of all these objects is the
same it's zero zero which is why they
always start in the ground
so they always kind of embed themselves
in each other
that's why so i'm just trying to move it
over to the top platform
so sometimes it gets a bit confusing in
3d space so it's easy to use the the top
view
i am using a trackpad as i said at the
beginning this is much easier if you
have a mouse
uh gravity will come to effect at some
point so it doesn't matter that these
things are currently floating
next thing we need to do is make a goal
so the goal of this game will be the
player tic tac has to push the ball into
a goal
again new scene very simple
making another spatial root note because
this goal will not move around the scene
that's the wrong kind of node
i'm a fool
i had a spatial node
we do not need an audio stream player
the spatial will be named goal as a
child of this goal spatial node we're
going to add a mesh instance once again
and uh
so yeah we're going to make a very
simple game where you have to push the
ball into goal into this goal we're
going to call create a cube
what color should this be
this is
very complicated decision making things
certain colors uh let's go
cyan maybe
maybe maybe
it's that's pretty gross that's probably
the nicest color we've used so far today
i'm gonna
rearrange this a little bit and create
the static uh collision body
because it doesn't need to move
and we're going to duplicate goal 1
after renaming it
no i don't duplicate i'm going to scale
it a little bit and then i'll duplicate
it
smush it a bit
smoosh it like that and smoosh it that
way so it's like a pillar
make it really tall
that's good enough now i'm going to
duplicate it and move it over a little
bit with the move tool
that's a goal i recognize that anywhere
it's kind of goal posts really
yeah that's good that's a goal
so i can see someone kicking a football
through that i'll save that as
goals.tscn
and uh i'll return back to my
environment scene and you guessed it
i'll link
the goal scene into the environment
scene
with the link button bring in the goal
amazing
i'll move the goal somewhere maybe at
the upper level i think today
it doesn't really matter where it goes
that's a good spot for it i think
it's good
yeah look at that that's nice goals over
there that's pretty nice our game is
taking shape
amazing
now we need to make
a little pickup because this is a video
game
we'll make a little pickup that maybe
does something if we get time it's a
video game so video games have pickups
it's very traditional again another
scene
we'll add an area so an area is
something that exists to be collided
with it doesn't necessarily have any
visuals it just has an area that can
tell some part of your game that
something else has collided with it
so
it's a really useful kind of spatial
volume that
has a thing inside or doesn't have a
thing inside it but can detect something
being in there
inside our area we will add a mesh
instance because we're going to add a
cube inside it because you know
everything's a cube everything's a cube
we'll uh go create a new color what
color should this be that's the real
question
maybe do we have a dark purple maybe
yeah oh yeah there we go
our pickup is dark purple
we'll add a collision shape to it
because it's a thing that exists in the
world it needs to be collided with
and we'll go over to the shape and add a
cube to our collision shape because the
cube's collider is also a cube
box not cube yep okay
uh yep
okay i've messed up the child there we
go they both should be child of area
rather than a child of each other there
we go
i'm going to rename the area to pick up
and save the whole scene pickup.tscn and
again back in environment i'll add my
pickup
so i'll select an environment and link
in the pickup
so we've got a nice pickup sitting in
our environment now
i'll move it over into the corner maybe
good spot
fantastic
so the goal of our game is to push the
ball through the goal and close the
pickup it's a very complicated video
game it's going to make a lot of money
uh
once we've done that i'll save it so
you'll notice we haven't coded anything
yet so
it's probably time to code something if
you run the game right now it will do
absolutely nothing
so
you'll see that is running uh paris and
tim's game thanks tim for helping me
build this game originally
we're gonna add a script now to make it
actually do something
i'm gonna click the player
i'm going to right click on it and go
attach script
and it's going to ask me what sort of
script i want i'm going to say i would
like a gd script
i've got to support c sharp gd script
it's kind of native scripting and visual
scripting which is kind of a block based
one today we're going to use gd script
which is a python inspired syntax but is
not python
it's a it's a really good little
language
it's going to ask us what to call it
we're going to leave it by the default
we're going to click create and it's
going to open up the inbuilt editor you
can use vs code or any other editor you
like but goto has a competent perfectly
communal in inbuilt editor
we're going to gloss over this a little
bit to be quick but we're going to get
it done so we're going to create a
variable
with the var keyword
we're going to call it move speed we're
going to set it to 500 completely
arbitrarily
programming is about making numbers up
as we know and video game programming is
doubly about making numbers up
we're going to create a direction
variable which is a vector3 which is a
vector with you know x y and z
so once we've got our move speed and our
direction
we're going to continue going on here uh
vector three if you're not used to it is
just it stores three elements so for
people are confused by that it has x y
and z or whatever you would like to it's
got three components well we'll use it
as an x y and z
it represents a direction uh we
obviously need gravity as well
so gravity in our little world is going
to be
9.8 i'm not sure where i got that from
but uh obviously has no relationship to
the real world but we'll see how it goes
also velocity uh velocity is important
in 3d space so our velocity is also
going to be a vector3
and uh
that's all we need uh we're going to
ignore ready so that doesn't really do
anything
uh ready it's called when a node enters
the scene in godot we don't need to do
anything special right now
i'm going to create a new function
called physics process which is the
thing called every physics tick
so goto has a bunch of predefined
functions we can use to manipulate our
game world
they'll start with underscore
so anything you make starts with no
underscore anything that got a splice
starts to underscore we're gonna set our
direction to
nothing zero vector three zero zero zero
so we're trying to get you excited about
gotta rather than teach you goto so i'm
gonna gloss over this a little bit
physics process gets kicked called every
time the physics tick happens with the
delta which is the time since last tick
so the reason that might be different is
the frame rate might be different to the
physics tick so this lets us account for
the difference
so if input
is action pressed so we're going to
check if
a certain action in the action table ui
left which is whatever key we've mapped
to left using god as action table and
i'll show you where that's set in action
in a second goto has a really powerful
input system that lets you set
named actions to certain keys so you can
check for an actual key or you can check
for a left right whatever it's a lot
easier to name things like left or right
so you can allow players or yourself to
remap things
so we're going to duplicate that for
left right up and
uh you guessed it down i can't type
i might get the the directions wrong but
i'm just going to take a guess right now
so
left is uh
x1
ui right is going to equal 2 minus 1
minus 1
yeah
and
yep
and we need so plus one for left minus
one for right
and z is our up
lowercase said not uppercase uh one
and
down
will will be uh
[Music]
minus one
right so yeah xyz
we want these keys to be able to move
the player around in the scene
now i can go project settings and you
can see where these are mapped
so in the input map you can see the ui
right
is mapped to a key or a d-pad so it's
mapped to uh
right
keyboard right
you can add your own name whatever you
like uh this is lets you abstract the
action away from the platform that
you're running the game on because goto
supports random consoles and ios and
gamepads and so on and so on and android
whatever you like
next thing we need to do is we're going
to normalize the direction so no matter
what direction we go when we're going at
the same speed so we're going to go
direction equals direction.normalized
if you want to do real game dev you need
to be okay with 3d movement it's not as
scary as it seems like it is
it's often
seems a lot scary than it actually is
it's quite okay
so
next thing
we're going to go
d equals d times move speed times delta
which basically makes it move at a nice
speed because we don't want to zoom off
in the distance too fast
that's pretty useful
so because this is being called every
physics tick we use the delta there as
well
uh because
if the frame weight
or the physics rate was inconsistent
then
not multiplying it by the delta would
mean the movement speed was jolty uh not
nice and smooth so this makes it nice
and smooth based on how your computer is
handling it
so
that just makes sure that handles it
properly
next thing we uh
if
we we want to fall faster than we jump
so if our velocity
on y is greater than zero so if we're
not jumping then we fall uh
if we are jumping then
the gravity is a different rate again
so video games are basically controlled
lying so gravity will affect us
differently when we jump basically uh
it's kind of like coyote time where you
know in the old cartoons when the kodi
falls off the uh the edge after being
off the edge already for a brief second
video games are basically that on a mass
scale
next thing we need to apply some gravity
so each physics step uh velocity on y
we
add some gravity
which is
multiplied by delta so it doesn't add
all the gravity at once
otherwise it'll just be be awful
that's uh
that's that
so once we've done that we also got
velocity.x equals direction.x so they're
the same
velocity is a three-part vector we also
need to z so direction.z so we only want
to modify the uh the y the the gravity
component of velocity we're not
modifying their otherwise velocity
so now we're going to actually make the
player move
so we're going to go velocity
and the velocity started at zero so
we're going to end with an actual
velocity we keep using
so we're going to use a function called
move and slide which is part of gotto
which basically
moves and hits stops you from hitting
something environment if it hits
something it comes to a stop
every game engine comes with an
equivalent of this function
move and slide is really quite useful
you can command click or control click
on
the function there and it gives you a
nice definition
moves the body along a vector if the
body collides with another body it will
slide along and stop
this means you don't have to calculate
all the fancy maths to move something
around in 3d space yourself and just
lets you use got it to do it so we floss
a velocity and a vector telling it which
way is uh up
and y is up
why why is up up is up
we also
want to be able to jump so if
is on floor which is another feature of
gotto
if we come and click on it it uh
returns true if the body is on the floor
so yeah it's very useful only updates
when calling move and slide uh it's
because the physics engine knows if
something is colliding with something
else that means it's on the floor
physics math can get hard really quickly
uh so we're gonna check if he's on floor
and input is action pressed
we're going to leave that blank for a
second and we'll come back to that
velocity dot y equals -10 so we want to
jump
yep 10 not a lot of 10 sorry yes
we want to go up that was an inverse
jump so if if we're on the floor and the
action press which will create the
second
is uh pressed so we're going to go into
our project settings
and in the input map and we're going to
go find game underscore jump
and click add
a game jump is at the end now i'm going
to map a key to that jump is a space bar
whoops
i want to map it to spacebar not control
add key space okay so now game
underscore jump action is mapped to
spacebar
so now i can provide the game underscore
jump action in that is action press call
it auto completes for me god is great
that's everything we need to do for now
in the script for our player so i'm
going to save player.gd with command s
or control s and go back into the
environment
i'm going to click my player
and the play now has a script attached
to it you can see over on the right side
there in the inspector player to duty
now i'm going to push command r to run
it and absolutely nothing will happen
because we haven't got a camera that was
deliberate by the way
very smooth it is doing things under the
hood but nothing is happening that we
can see
so i'm going to click the environment
and click plus for a new node and search
for a camera
and you'll see there's a camera node
guys got a bunch of cameras you've got
ar cameras and vr cameras all sorts of
stuff
you can see this frostum thing which
shows us where the camera is pointing so
you can see where the camera is pointing
with a little preview button so i'm
going to rotate the camera to have a
nice angle to make it slightly more
useful
that's slightly more useful a little bit
more rotation down and then we'll have a
nice camera
now if i run it we should have an actual
view
yep look at that oh we can move the
player with the mouse with the keyboard
you can even jump look at that
the the it falls a lot quicker than the
red it moves out which is great
everything seems to be working
the camera is not following the player
which is uh not very good but he he move
and slide works he hits the wall
they hit the wall it's doing very well
so far
we're going to continue improving this a
little bit
i can jump off the world too way
camera didn't follow me though so i'm
going to go back to godot
and i'm going to drag the camera onto
the player so now the camera is a child
of the player
the camera will now follow the player uh
this is a very crude camera follow you
could write a nice little script so the
player follows the camera follows the
play around like mario 64 so you have a
cameraman like a lerp and stuff a nice
flow but now the camera is following the
player at least so
this is a a lot better
i'm going to fix the key mapping because
the key map is actually backwards so i'm
going to go into
yeah okay just backwards forwards yep
go back into the gt script and modify
the key mapping
so
[Music]
plus equals one
yep and we're going to run that again
oh no
it's just rotated slightly sorry i've
got my keys around the wrong way so i'm
going to go ui
up
ui
down i'm 90 degrees relative to where i
needed to be
so you are left you are
right our left was forward
yeah
no strings so you need to yep there we
go
okay
perfect look at that now i can actually
control it
everything's working
now i can drive around get up the ramp
the a bit easy but there you have it
so we're going to make the goal work
next
i can push the ball oh look at that
okay there's no knowledge for the game
that it's called the goal though so
we're going to go into the environment
we're going to click on the uh ball
i'm going to tick the little box that
says can sleep
the ball's been falling asleep when it
doesn't move which means it doesn't
respond to physics very well
now pushing the ball around will be a
nice pleasant rolling experience
because the game was kind of putting the
physics system to sleep
look at that it rolls nicely instead of
just flying forward beautiful
i'm gonna add a little bit of code to
make the goal know when the uh the ball
has gone through it
so
first thing i'm going to do is go into
environment and add a script to the
environment
which will let us reset the game so this
means we have to restart the game
constantly
so uh tweaking the game is a lot easier
when you can reset the game in the
process uh call which is called every
frame i'm gonna go if input key pressed
key enter so unlike before where we
mapped a nice action we're going to
brute force map the enter key i'm going
to go get tree which just gets the whole
node tree and reload current scene so
now when i push enter the game resets
look at that beautiful
extremely useful
with that in place i'm going to go to
the uh
the goal
on the upper platform i'm going to add
an area so i'm going to move the scene a
little bit so i can see what's going on
i'm going to click on the upper floor
and i'm going to add an area to that
which is the same kind of volume thing
you saw earlier
there's the area
so i'm not adding the goal to the goals
scene i'm actually adding the goal to
the the main environment scenes it kind
of is overlapping the place where the
goal is in that scene just for detection
purposes and to make scripting slightly
easier so in that area i'm going to add
a collision shape
collision shape
and add a
box so this box basically says what
shape is the area that is detected this
is the area the invisible area that can
detect when something is inside it so
you can see the invisible area
represented by those uh
those lines
anytime the ball goes through the area
we score a goal this is a very easy game
i'm going to make a tiny bit thinner
just slightly less easy
that's better yep okay now it's not so
so easy uh with the goal ready to go we
need to actually do the scripting
component so we're gonna add a script to
the game to let us score that goal so
i'm going to click on the area
i'm going to go
node
and you'll see this node emits a bunch
of signals
so these signals are things that can be
connected up to code to make it do
things so the area emits a body entered
signal and tells us which body entered
it so i'm going to click body entered
click connect
it's going to ask me where i want to
connect it to
i'm going to connect to the environment
which
adds a on area body entered function to
the environment script that we created
so i'm going to delete the contents of
that and inside that i'm going to go if
body
is rigid body
which basically means it can only be the
player
i'm going to print hooray goal we
haven't got time to make a ui today but
uh this will print a nice little message
to the console when the player goes
through the goal
sorry the ball goes through the goal
i'm going to move up here i'm gonna push
the ball through the goal
and it says hooray goal
because it knows the ball has gone
through because it can only detect the
ball the ball is the rigid body
amazing
that's pretty much our whole game
i'm going to go quickly and make the
power up do something because we've got
a little bit of a second to do that i'm
going to click on the cube
i'm going to add a script to it
everything needs a script attached
script pick up inside that script i'm
going to
uncomment process so every single frame
please rotate so we're going to rotate
dot x underscore x deg to rad
so process is called literally every
frame
so we're going to uh basically rotate it
uh at the delta rate
on the x and rotate it on the y
we're going to run it and narrow our
cube we'll spin like a proper video game
power up so that was gotto hope you
enjoyed it uh please dive into it and
build more things or extend this silly
little game please tweet me little any
questions you have uh thank you for
watching hope you're all staying safe uh
you can export your game to mac linux
android consoles a whole bunch of things
thanks very much
hello everyone and thank you so much for
your talk paris i there was some great
chat in the
chat room during that which was really
great to see
um if you had any questions for paris i
hope you asked them during the chat that
was a really great presentation seems
like a really cool tool
uh next up we have a break
is a great time to get up stretch your
legs stretch your hands eat some food
drink some coffee pat your cats send
photos of the cats to the pets of lca
channel and venulis
or go to the linux agm which is at 12 30
and if you're a member of linux
australia you should have got an email
about that
so the next talk in this room is after
lunch at 1 30 pm aedt
uh from russell coca it's 20 years of
nsa security enhanced linux
retrospective
so i'll see you all uh there or in later
talk or later on
have great have a great lunch