0% found this document useful (0 votes)
27 views28 pages

Creating Your First 32d Game - Lesson 1 - Student Guide - v01

This document serves as a student guide for building a 3D game using Unreal Engine, focusing on collision detection. It outlines a series of activities designed to teach essential programming concepts through the creation of a parkour course. The guide emphasizes the importance of collision detection in gameplay and provides step-by-step instructions for navigating the Unreal Engine interface and implementing collision volumes for game objects.

Uploaded by

sivas39789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views28 pages

Creating Your First 32d Game - Lesson 1 - Student Guide - v01

This document serves as a student guide for building a 3D game using Unreal Engine, focusing on collision detection. It outlines a series of activities designed to teach essential programming concepts through the creation of a parkour course. The guide emphasizes the importance of collision detection in gameplay and provides step-by-step instructions for navigating the Unreal Engine interface and implementing collision volumes for game objects.

Uploaded by

sivas39789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Build your first

3D game: Learn
collision detection
in Unreal Engine

Student guide
Activity 1 | Build Your First 3D Game: Learn Collision Detection in Unreal Engine

Overview
Unreal Engine is an immersive 3D game engine that powers
some of the most popular video games in the world. While
some games require teams of professionals to produce
a final product, you can get started with no experience.
Rather than focusing solely on basic concepts of computer
programming, you’ll jump straight into building a video game.
This series of activities is designed to guide you through the
process of creating a 3D video game while highlighting the
important computing concepts along the way. We hope the
promise and excitement of building a video game will give
you the context and motivation to learn essential computer
programming concepts.

This entire program contains five (5) Hour of Code activities


that combine all the concepts and instructions you need to
complete a 3D video game that you can play and share with
friends. The activities and included project files are designed
to be done in order from beginning to end or you can select
any single activity to complete individually. Each activity
holds exciting new challenges and discoveries that unlock
the power of game development using Unreal Engine.

Build your first 3D game: Learn collision detection in Unreal Engine 2


About this
Activity
In this activity, you will learn how to build a
parkour course to get the player through a
simple hallway, and across a treacherous
Getting Started
void. For our purposes, parkour refers to
the player running and navigating jumps of If you have not
varying difficulty over a deadly void. The downloaded Unreal
jumps you will be setting up will give the Engine and the Hour of
player a variety of challenges to overcome. Code Project, see the
Getting Started Guide to
You can make the parkour challenges as easy do so. If you have, open
or difficult as you like. Be mindful that difficulty the project and begin!
does not always equal fun. You may think your
level is too easy to complete, but this may be
because you are the designer and have played
through your level many times. Be sure to take
all the feedback from your play-testers very
seriously, because this will make your game
more enjoyable for a wider group of players.
The more play-testers you work with, the
more successful your game will become.

Build your first 3D game: Learn collision detection in Unreal Engine 3


Programming
Concepts
You will be learning about collision detection and
its importance in computer programming and game
development. In the real world, it’s easy to understand
how you can sit in a chair, stand on the floor, or hit a ball
because they are all physical objects. In a virtual 3D world,
the concept of physical objects needs to be defined in
code. The moment when two objects collide or overlap is
called a collision. When objects collide, Unreal Engine can
identify which objects collide and how each object should
react. You will learn the critical importance of collision
detection in this activity.

Additionally, this activity will give you a chance to


get familiar with navigating Unreal Engine user interface
in the Viewport.

Open up the project and let’s begin!

Build your first 3D game: Learn collision detection in Unreal Engine 4


Opening the
Game Design Map
To start working, we must open the correct map within the project.
We will do this by opening the Content Drawer. The Content
Drawer is located in the bottom left corner of the User Interface.
Click the Content Drawer button to open it.

fig 1

Build your first 3D game: Learn collision detection in Unreal Engine 5


Navigate to Content > Hour_of_Code
> Map folder, and double-click on the
Level HoC_World asset to open the
map we will be using in the guide.

fig 2

You should now see this when it has


opened. See image below.

fig 3

Build your first 3D game: Learn collision detection in Unreal Engine 6


Reviewing the
Interface
The following set of activities assumes you have some familiarity
with the Unreal interface, so we will only cover the areas of the
UI (User Interface) that we will be using. We will also be using the
default UI setup that ships with Unreal.

Locate the Content Drawer. This can be found at the bottom of the
screen. By clicking on the button indicated by the arrow, you can
show the sources to make navigation through the folders
much easier.

fig 4

Build your first 3D game: Learn collision detection in Unreal Engine 7


You can also change the color of the
folders to make it easier to find them.
Let’s change the “Hour_of_Code” and
“Blueprint” to a blue color. Right-click
on the folder and choose Set Color.
Then choose a blue color from the
Color Wheel.

fig 5

The Place Actors panel contains assets


like Lights and Trigger Volumes. It can
be access by clicking the button in
the toolbar at the top of the interface.
These assets will be available in every
project you create. This is different than
the Content Drawer because the
Content Drawer will also contain assets
that you can import from 3D design
programs like Autodesk’s Maya, 3D
Studio Max, and Blender, or create here
in the engine.
fig 6

Build your first 3D game: Learn collision detection in Unreal Engine 8


We will be doing most of our work in the Viewport. This is the large area in the middle of the
screen where you will place assets from the Content Drawer.

Actors
The term "Actors" is used to identify the various objects or elements that are in a Level.
While the phrase is commonly used to identify people in films and TV, it is also a term used
to refer to different types of objects in a level seen in the viewpoint.

When navigating in the Viewport there


are a few different ways to control the
camera. First, the following camera
controls only require use of mouse.

• Hold LMB (left mouse button) and


drag the mouse to dolly the camera
forward and backward, and pan it
right and left.
• Hold RMB (right mouse button)
and drag the mouse to pan the
camera right and left, and up and fig 7
down to track.
• If your mouse has a scroll wheel, you
can use that to zoom in and out.
• Hold MMB (middle mouse button)
and drag left and right to truck, and
up and down to boom.

Build your first 3D game: Learn collision detection in Unreal Engine 9


Next, If you have ever played a first-person game on a computer,
you probably used the WASD keys to move around, and these
controls will feel natural. The WASD controls can be used whenever
you hold down the RMB. If WASD is too difficult, you can use the
arrow keys as well.

Do not forget to hold down the RMB while using the following
keyboard keys:

• W forward
• S backward
• A left
• D right
• E up
• Q down

You can also press the F key to frame any selected asset or actor.
Select an asset in the viewport, then press the F key and see what
happens. Select another asset and press the F key again.

Next, open the Levels panel. This can be displayed by navigating to Windows > Levels.
Click and drag the window by the tab to dock it next to the World Outliner so we can use
it later.

This window contains examples of


what each activity could look and
feel like. As you progress through
the activities feel free to click the
eyeball icon to view the examples.
We highly encourage you to work
through the activities in order, as each
lesson builds upon the previous.

fig 8

Build your first 3D game: Learn collision detection in Unreal Engine 10


The Details window, also referred
to as the Details Panel, will show
editable attributes of any Actor that is
selected in the Viewport. Any asset
placed into the Viewport is referred
to as an Actor. You can think of them
as similar to actors on a stage, but
they are Actors in your game. Select
the PlayerStart Actor and you will
see the Details Panel update.

fig 9

Build your first 3D game: Learn collision detection in Unreal Engine 11


If you need to deselect an
Actor, hold Ctrl and click the
Actor. Or press the Esc Key to
deselect all selected Actors.

fig 10

We will also be using the World


Settings. To open this window,
open the Window menu and select
World Settings. This panel contains
information about the game’s 3D world.
For these activities, we will be working
within the Persistent Level, and we will
only be editing the world settings for
the Persistent Level.

fig 11

Build your first 3D game: Learn collision detection in Unreal Engine 12


Let’s Play!
Let’s jump right in! Click the Play button at the
top of the screen, or press Alt + P.

fig 12

Move your mouse over the Viewport and click the left mouse button. This will give you control
of the player. You can use the mouse to look around, and use the following buttons to move;

W = move forward
A = move left
S = move right
D = move backward
Space = jump
Hold Shift while moving = sprint

Try walking onto the circular platform over the pit. What happened?

Press the Esc key on the keyboard to leave the game and return to edit mode.

Build your first 3D game: Learn collision detection in Unreal Engine 13


You’ll notice that your character falls
through the platform, and lands at the
bottom of the pit. This is because the
platform has no collision associated
with it, it is only being drawn visibly
in the world. The game doesn’t yet
know that the player should be able
to stand on this platform. Let’s create
a Collision Volume for this asset.

fig 13

Collison Detection
As you may have experienced in this test, just because an object appears to be solid doesn't
mean that it will behave that way. In the physical world, it's easy to predict and observe two
objects colliding. When dealing with colliisions in a simulated environment, the attributes
of objects need to be defined along with their positions. Math formulas in the code will
calculate if two objects are overlapping, thereby causing a collision. When the collision is
detected, it will perform a specific action assigned by the programmer. In our first example,
the collision doesn't exist, so the player couldn't stand on the platform. To correct this, we
will need to define a collision area around the platform so we can have the player stand on
the platform.

Some fantastic mathematical formulas are capable of calculating collisions. Without them,
the games would be pretty boring. Thank you, math!

Build your first 3D game: Learn collision detection in Unreal Engine 14


Fixing the
First Platform
To fix our problem with the platform, we will need to
establish a collision area for that object. The object
has a shape and texture that allow it to be visualized Lost?
in the game, but this is separate from its collision
properties. We need to add a collision volume as an If you are having
invisible shape that is attached to the object. We can trouble navigating to
make the collision match the shape of the object or the first platform, press
customize the shape to fit the needs of our game. the number 1 on your
keyboard and then
Most of our work in this project will be using a simple
click and hold the left
collision shape that closely matches the object shape. mouse button to look
left/right and move
Select the platform Actor in the Viewport forward/backward.
and press Ctrl + E, this will open the
Static Mesh Editor for this asset.

If you need to deselect an Actor, hold Ctrl and click the Actor. Or press the ESC key to
deselect all selected Actors.

NOTE: You can also open the Static Mesh Editor by navigating through the Content Drawer:
Content > Hour_of _Code> Static_Meshes and double-click on the SM_Platform_M asset.

fig 14

Build your first 3D game: Learn collision detection in Unreal Engine 15


With the Static Mesh Editor open,
click the Collision button in the
toolbar and choose Add 10DOP-Z
Simplified Collision. This will
create a simple collision volume
that fits around the platform.

fig 15

You will see a green shape appear


around the platform. It will not fit
exactly to the platform, and it does
not need to, it just needs to be close
enough to work for our gameplay
purposes. You can always scale, rotate,
and move the collision around to fit
your gameplay needs.

Click the Save button in the top left to


apply the changes, and then close the
Static Mesh Editor by clicking the X
fig 16
button in the top right of the window.

Build your first 3D game: Learn collision detection in Unreal Engine 16


Review the Player
Collision Definition
Let’s take a moment to look at the collision on the
player character (aka pawn). This will be important for
understanding how the player’s collision volumes interact
with the collision volumes of objects in your level.

To get a copy of the character, select the Hour_of_Code


folder in the Content Drawer, and enter “character” in
the search bar. Then click and drag the BP_HourofCode_
Character into an open space in the level. Then press
Alt + C, to show the collision on all objects in the level.

fig 17

Build your first 3D game: Learn collision detection in Unreal Engine 17


You will see a wireframe capsole volume that makes up the character’s
collision. This capsule collision volume is used to determine if the
character can walk on other collision volumes, and in the case of
taking damage, when and where the character should be affected.

If you look at the platform you will also see the collision
you have created. Can you spot the other collision
volumes for all the other Actors within the level?

Press Alt + C to toggle OFF the collision preview in the


viewport, then select the character we just added and press
Delete on the keyboard to delete it from the level.

Note: Collision can also be toggled by navigating to the


Show menu in the viewport.

Hit-Box
Have you heard of the term "hit-box" in video games? In a fighting game for example, the
hit-box is the defined area where the payer will take damage when hit. It's also possible that
a hit to the head can cause more damage than a hit to the arm. This is all done with collision
volumes such as the ones we are working on in this project.

Look at the player example in the image above. Can you see the collision volume shape that
surround the body? Notice how the collision volume doesn't match the shape of the body
exactly. lf you've ever been hit by a projectile that "technically" missed your player, this is
the reason.

The basic reason for a simplified collision volume is because of compute resources. A more
exact shape would increase the computing power which would slow the responsiveness of
your game. Therefore, as a Game Developer, you would have to balance precision against
the most dreaded foe of all ... lag!

Build your first 3D game: Learn collision detection in Unreal Engine 18


Now that we have created Collision
on the platform, and we have a
better idea of what collision does for
our player, we should playtest our
platform to make sure it works. Play
your level again and double-check
that everything is working correctly.
Does the player fall through the
platform? Go back and double-check
your work.

fig 18

Build your first 3D game: Learn collision detection in Unreal Engine 19


Adding More Platforms
with Duplicate
Great! You should have the player landing on the first
platform. Now we need to add more platforms so the player
can safely reach the other side. As a Level Designer, you
need to think about efficient ways to accomplish tasks.
This will take less time to complete projects and will likely
result in better projects. In this case, we are going to use
a shortcut that quickly copies our platform so we can
place the platforms needed to get across the hallway.

We can duplicate the platform a few times to create a


parkour path across the pit. First, select the platform.
Using the move gizmo, hold the Alt key, then click and drag
on the red arrow of the gizmo to duplicate the platform
down the hallway. You will need to let go of the Alt once
you have created the duplicate, then hold it again to
create a new duplicate. Once you have a few platforms
in place, test your level to see if you can get across.

If you are having difficulty seeing the


red arrow on the move gizmo, navigate
the camera to a location above the pit.
Or press the 7 key on the keyboard
to move the camera to the camera
bookmark above the pit. From this
position you will be in a better position
to work, as seen in fig 21.

fig 19

Build your first 3D game: Learn collision detection in Unreal Engine 20


Handling
Failed Attempts
If you fell in the pit, you probably noticed that your
character is unable to make it out. This is referred to
as a “showstopper” or “soft lock”. The game hasn’t
ended and there’s no way for it to progress.

Since the game engine doesn’t know the goal of your


game, it is only doing what you tell it to. If you want the
player to be “eliminated” or “respawn” you must add
that manually. There are many ways to tell the game
what you want it to do, and once you complete this
activity you will have a better understanding of how
to tell the Engine to behave in a specific manner.

Showstopper Bugs
When the player falls into the
pit, they are stuck and can’t get
out. This can be called a bug
because the game can’t go on.

We can address this bug by placing a


Pain Causing Volume in the pit that will
reset the player and send them back to
the Player Start.

In the Place Actors tab, type “pain” fig 20


into the search bar. Then drag a Pain
Causing Volume into the pit.

Once you have placed the volume in


your level, press W to use the move
gizmo and press R to use the scale
gizmo. Place it into a location where the
character’s collision will touch it when
they fall anywhere into the pit.

Build your first 3D game: Learn collision detection in Unreal Engine 21


If you are finding it difficult to navigate,
here are a few pro tips.

• Press 7 on the keyboard move the


camera into the location seen in the
above image.

or…

• Select an actor in the viewport by


clicking on it, then…
• Press F, to frame the selected actor in fig 21
the Viewport, then….
• Use the scroll wheel to move the
camera farther away from the framed
object, finally…
• Hold the Alt key on the keyboard and
click-and-drag in the Viewport to
orbit around the framed object. Avoid
clicking on the gizmo when you want
to orbit around the object.

Play the game again and check that your character resets when they jump into the pit. You
might need to move the Pain Causing Volume around a little bit to get it to work the way
you want.

Build your first 3D game: Learn collision detection in Unreal Engine 22


Detect Falling into the Void
Now that you can jump across to the
end of the pit, try jumping off the large
island at the end of the level. Yeah, that
seems unsafe, but is it? Go ahead, give
it a try. What happens?

Press Esc to stop the game and press


the number 1 to reset the viewport back
to the first camera bookmark.

It looks like we are missing yet another


collision. In this case, the player just
keeps falling. This is because the game
doesn’t know that you want to restart
after falling a specified distance. We
will address this issue by enabling the
Kill Z Bounds, a plane that will reset the
character when it touches it.

In the World Settings panel, scroll


down to the World section and toggle
ON Enable World Bounds Checks. You
may have to click the down-arrow to
Show Advanced options. Next, open
the World section and set the Kill Z to a
value of -500.

Play the game again, and now after


falling into the void the character will
respawn at the beginning of the level.
Now let’s create a parkour course to
reach the next location.

fig 22

Build your first 3D game: Learn collision detection in Unreal Engine 23


Build a Parkour Course
to the Next Level
Now it’s time for you to get creative! Once the player
has made it across the platforms, they see exciting new
destinations that are floating in the sky. The only way to get to
the next destination is across a gap. This is where you come
in. In this exercise, we will show you how to place a floating
island in the world. Then, it will be up to you to use your skills
and experience to create a path to the next destination.

Navigate the viewport camera above the gap as


shown in the image below, or press the 6 key on the
keyboard to move the camera to this location.

fig 23

Build your first 3D game: Learn collision detection in Unreal Engine 24


You will add some small floating islands
to reach the next location. They can
be found in the Content Drawer under
Content > Hour_of_Code > Static_
Meshes folder. Click and drag one of
the SM_FloatingIsland_S assets into
your scene.

By dragging the SM_FloatingIsland_S


asset on top of another actor, we can
quickly place it in our level at a location
and height more efficiently. See the
image below. fig 24

Use the arrows on the Move gizmo to


move this first floating platform into
your desired location. If you do not see
the Move gizmo, select your floating
island and press the W key.

fig 25

With one floating island in the scene,


you can duplicate it just like you did
with the platforms. Hold Alt + click and
drag one of the arrows of the move
gizmo to create another floating island.
Create a path that will allow the player
to reach the far platform. It will appear
similar to the image below.

fig 26

Build your first 3D game: Learn collision detection in Unreal Engine 25


Pro-Tip:
Want to quickly test
your jumps in the game?
Click the three dots
to the right of the
Play button. Change
the ‘Spawn Player
at…’ option to Current
Camera Location, then
click the Play button to
start your player at your
current camera position.
Make sure you’re above
solid ground before
pressing Play. Don’t
forget to change it back
to Default Player Start
when you’re done.

fig 27

Build your first 3D game: Learn collision detection in Unreal Engine 26


Again, we want to play-test this, so
try and jump from one platform to the
next. Work to createa path where your
players will enjoy traveling through.

Be sure to Save your work by navigating


to File > Save All, or by pressing
Ctrl + Shift + S on the keyboard.

fig 28

Build your first 3D game: Learn collision detection in Unreal Engine 27


Challenge:
What's Next?
Can you build a set of platforms that gives the
player a few different choices to get to the In the next Hour of
next section? Players enjoy having choices, Code activity, we will
it creates a more non-linear experience. continue to build a
more challenging game
by adding a moving
platform, as well as
Game Design Fun: adding a checkpoint
to help ease some of
the frustration that
Due to the settings where collision volumes comes from having to
don’t render visibly in-game, you can create a play the same section
gameplay scenario that would never be possible over and over.
in the real world. Try building an invisible
bridge, however, keep in mind that players
don’t respond well to invisible walls. If you use
collision to ‘box’ a player in, then you should
always give the player a logical explanation of
why they can’t access a location. You can find
Blocking Volumes in the Place Actors panel.

Build your first 3D game: Learn collision detection in Unreal Engine 28

You might also like