Start Your Game Creation Journey Today! (Godot beginner tutorial)

Coco Code
18 Oct 202322:02

Summary

TLDRThis tutorial guides beginners through creating a 2D platformer game using the free, open-source Godot engine. It covers installing Godot, setting up a new project, and designing a scene with a background, ground, and character. The script teaches adding animations, basic movement controls, and refining player interactions. By the end, viewers will have built a functional game and learned foundational game development concepts.

Takeaways

  • 🚀 **Start with Basics**: When learning a new game engine, begin with creating a simple platformer game to understand the fundamentals.
  • 🌐 **Choose an Engine**: Use Godot, a free and open-source engine, for creating your first game project.
  • 📂 **Project Structure**: Organize your projects by creating a new directory for each new project within Godot.
  • 🎨 **Scene Creation**: A scene in Godot acts as a container for all game components, both static and dynamic.
  • 🖼️ **Background Setup**: Use texture rectangles to create backgrounds and adjust their properties to fit the game window.
  • 🧱 **Ground Creation**: Utilize tile maps for creating ground and other scene objects, allowing for easy painting of tiles.
  • 🐸 **Character Setup**: Create a character with a sprite for visuals and a collision shape for physics interactions.
  • 🔗 **Subscene Utility**: Save branches of the scene as subscenes to facilitate reusability and organized editing.
  • ▶️ **Game Testing**: Regularly test the game to check for collisions, character movements, and overall gameplay.
  • 💻 **Scripting Movement**: Use GScript to add movement control to the character, making use of built-in templates for character movement.
  • 🔄 **Input Mapping**: Define custom key mappings for character control in the project settings for a more tailored input experience.

Q & A

  • What is the recommended game engine for beginners according to the script?

    -The recommended game engine for beginners is Godot, a free and open-source engine that allows you to create your first dream project.

  • What is the first step in creating a new project in Godot?

    -The first step in creating a new project in Godot is to visit the official website, download the latest version of the Godot engine, and then create a new directory to hold all future Godot projects.

  • How do you create a new scene in Godot?

    -To create a new scene in Godot, you go to the top left, click on 'Other Node', select 'Node' from the 'Scene' window, and click 'Create'. This will be the root of the scene, and all other components will be children of it.

  • What is the purpose of saving the scene with a specific file extension in Godot?

    -Saving the scene with the '.dscn' file extension in Godot is to ensure that the scene format is recognized by the engine and can be easily located and accessed within the project's file structure.

  • How do you import a background image into your Godot project?

    -To import a background image into your Godot project, you drag the image into the 'FileSystem' section, which makes it a part of the project, and then create a 'TextureRect' node to display the image on the scene.

  • What is the 'TileMap' node used for in Godot, and how do you configure it?

    -The 'TileMap' node in Godot is used for creating grid-based levels. It is configured by creating a new 'TileSet', importing the terrain image, and then drawing the tiles on the scene using the 'TileMap' tab.

  • How do you create a character in Godot and what are the essential child nodes it should have?

    -To create a character in Godot, you create a new 'Node2D' called 'CharacterBody2D', which should have two child nodes: a 'Sprite' node to define its image and a 'CollisionShape2D' node to define what touches the ground and collides with other elements.

  • What is a subscene in Godot and why is it useful?

    -A subscene in Godot is a group of nodes that can be saved as a single entity, also known as a prefab. It is useful for organizing complex entities like characters and for making changes that apply to multiple instances of the same entity.

  • How do you add movement to a character in Godot using scripting?

    -To add movement to a character in Godot, you create a script attached to the character's root node, use the 'GDScript' language, and utilize a built-in template for moving 2D characters. The script checks for ground collision, jump inputs, and horizontal movement inputs to control the character's velocity.

  • What are the steps to create animations for a character in Godot?

    -To create animations for a character in Godot, you change the 'Sprite' node to an 'AnimatedSprite' node, import the animation frames, add them to the 'SpriteFrames' property, and then set the animation to play on load by selecting the animation and enabling 'Play on Load'.

  • How do you make a character's movement smoother in Godot?

    -To make a character's movement smoother in Godot, you can tweak the 'move_and_slide' function parameters such as 'max_speed', 'friction', and 'stop_threshold', and adjust the 'gravity' and 'jump' velocity in the project settings.

  • How do you customize the input actions for a character in Godot?

    -To customize the input actions for a character in Godot, you go to 'Project Settings', select the 'Input Map' tab, declare actions and key mappings, and then replace the UI action strings in the script with the defined actions like 'jump', 'left', and 'right'.

Outlines

00:00

🚀 Starting a Platformer Game in Godot

The paragraph introduces the process of starting a platformer game in Godot, a free and open-source game engine. It guides users through the installation of Godot, creating a new project, and setting up the main editor window. The focus is on creating a scene, which is a container for all game components. It explains how to create a basic 2D scene with a background, ground, and character. The paragraph also covers importing assets, setting up a tile map for the ground, and creating a character with a sprite and collider. The process of saving scenes and organizing the project structure is also discussed.

05:02

🛠️ Building the Game Environment and Character

This section delves into enhancing the game environment by resizing tiles for better visibility and adjusting texture filters for clarity. It introduces the concept of level design using tile maps, allowing for the creation of complex game levels. The paragraph also covers the creation of the main character, including setting up a sprite and a collision shape. It explains the importance of subscenes for organizing game objects and the process of testing the game to ensure basic functionality. The segment concludes with a brief on adding a script to the character for basic movement.

10:03

💻 Scripting for Character Movement

The focus of this paragraph is on scripting the character's movement within the game. It begins with a template script for character control and explains how to set up and configure the script. The paragraph addresses the importance of collision detection between the character and the game environment. It also covers how to implement and test basic movement controls using keyboard inputs. The segment concludes with a discussion on enhancing the character's appearance with an idle animation, which adds a dynamic element to the character's presentation.

15:03

🎮 Enhancing Character Animation and Control

This section focuses on refining the character's animations and control mechanisms. It starts with the process of adding animations for different character states, such as jumping and running, using the AnimatedSprite2D node. The paragraph explains how to implement these animations within the script to enhance the character's movement dynamics. It also covers tweaking the character controller's parameters for smoother movement and jumping. The segment concludes with a discussion on optimizing the character's movement response and the impact of these adjustments on gameplay.

20:05

🔄 Customizing Input Mappings for Better Control

The final paragraph discusses the customization of input mappings for the game. It explains how to define actions and key mappings in the project settings, allowing for a more tailored control scheme. The paragraph guides users through replacing UI action strings with custom-defined actions for better control over the character's movement. It concludes with a summary of the completed tasks and an invitation to subscribe for more content, highlighting the completion of all the outlined objectives for the tutorial.

Mindmap

Keywords

💡Godot Engine

Godot Engine is a free and open-source game development engine that allows developers to create 2D and 3D games. It is the central theme of the video, as the tutorial is focused on using Godot to create a platformer game. The script mentions downloading and installing Godot, creating a new project, and navigating its interface.

💡Scene

In the context of Godot Engine, a 'Scene' is a container that holds all the game's components, both static and dynamic. The video script guides viewers on creating a scene, which is fundamental to organizing the game's elements and setting up the game world.

💡Node

A 'Node' in Godot represents an object or entity within a scene. Nodes can be anything from visual elements like sprites to functional elements like colliders. The script describes adding child nodes to the scene and using different types of nodes like 'TextureRect' and 'TileMap'.

💡TileMap

A 'TileMap' is a node used for creating 2D levels by arranging tiles. The script explains how to set up a tile set and use the TileMap to paint the game's terrain, which is essential for designing the game's environment.

💡Sprite

A 'Sprite' is a 2D image used to represent characters or objects in a game. The video script includes instructions for importing a sprite image and setting it up within the game scene, which is crucial for visual game development.

💡CollisionShape2D

The 'CollisionShape2D' node defines the shape of a collision area for a game object. In the script, it is used to set up collision detection for the player character, which is vital for gameplay mechanics like jumping and avoiding obstacles.

💡Subscene

A 'Subscene' in Godot refers to a group of nodes that can be treated as a single unit. The video describes creating a subscene for the main character, which allows for easier manipulation and reusability of complex game objects.

💡GScript

GScript is a scripting language used in Godot Engine for writing game logic. The script mentions using GScript to create a movement controller for the character, demonstrating how scripting is used to implement gameplay mechanics.

💡Animation

The term 'Animation' refers to the process of creating movement or change in a static image to create the illusion of life. The video script includes instructions for setting up animations for the character's idle, jumping, and running states, enhancing the visual appeal and interactivity of the game.

💡InputMap

The 'InputMap' in Godot is used to define user inputs and associate them with actions. The script guides viewers on setting up key mappings for player controls, which is essential for creating a responsive and playable game.

💡Physics Layers

In Godot, 'Physics Layers' define which objects can collide with each other. The video script explains how to set up physics layers for the game's tiles, ensuring that the player character interacts correctly with the game environment.

Highlights

Introduction to creating a platformer game using the free and open-source Godot engine.

Installation process of Godot engine and initial setup for a new project.

Explanation of the Godot main editor window and its various panels and tabs.

Creating a scene as a container for in-game components in Godot.

Saving the scene and naming conventions for Godot scene files.

Setting up the 2D mode and creating the game window border.

Adding a background to the game scene using a texture.

Using anchor presets to ensure the background covers the entire screen.

Importing and setting up a tile set for the game's ground.

Creating a tile map and painting the ground tiles for the character to walk on.

Adding a character to the scene with a sprite and a collider.

Creating subscenes for better organization and reusability of game elements.

Running the game and initial testing of the character's movement.

Scripting the character's movement controller using GScript in Godot.

Fixing character collision with the ground by setting up physics layers.

Adding animations to the character for idling, jumping, and running.

Implementing smooth movement and jumping mechanics through script adjustments.

Customizing input mappings for character control beyond the standard arrow keys.

Completion of the tutorial with a fully playable basic platformer game in Godot.

Transcripts

play00:01

if you're just starting your game def

play00:02

Adventure or you're trying out a new

play00:05

game engine it's good to start with

play00:07

Basics Tod platformer game we'll create

play00:09

it in goo a free and open source engine

play00:13

that will allow you to create your first

play00:14

Dream project we'll be touching a lot of

play00:17

Concepts so stick to the very end to

play00:19

collect all their badges if some of the

play00:22

workflows require revision don't forget

play00:24

to explore video Chapters at the bottom

play00:26

of the video after each chapter you will

play00:29

receive a new badge first let's install

play00:32

godo visit the official website click

play00:35

download latest and then godo engine

play00:38

after installation you will be greeted

play00:40

with this screen press new project PR

play00:44

the puff and create a new directory that

play00:46

will hold all your future goo projects

play00:50

give your new project a name and click

play00:52

create folder that way you will have a

play00:54

nice structure for this and future

play00:57

projects as for the renderer select

play01:00

mobile option it's the best choice for

play01:02

2D game click create and edit this is

play01:05

the gdo main editor window here we'll be

play01:08

doing all of our work as you can see

play01:10

there are multiple panels and tabs which

play01:13

we be discovering along the way first

play01:16

thing we need to do is to create our

play01:17

scene scene is a container that gathers

play01:20

all the in-game components both static

play01:23

and the dynamic ones as you can see here

play01:25

in the top left goto gives us some

play01:27

starting suggestions but I would prefer

play01:30

to have a blank canvas click on other

play01:32

node and from this scare window just

play01:35

select default white node and click

play01:38

create this will be our root of the

play01:40

scene and all other components will be a

play01:43

child of it that helps to keep our

play01:45

project tidy before we'll start adding

play01:48

child notes we need to save our scene

play01:51

just click control or command s name it

play01:54

main. dscn which is a godo scene format

play01:58

and click save save after it's saved you

play02:01

can find it here in the file structure

play02:04

of a project congrats this is your first

play02:08

badge today we'll create only 2D

play02:11

elements so here at the top select 2D

play02:14

mode and zoom into the blue border it

play02:17

represents our game window our scene

play02:20

will consist of three main elements

play02:23

background ground blocks where our

play02:25

character will be able to walk and a

play02:28

character let's start with the first one

play02:31

today for all the graphics I'll be using

play02:34

this awesome free pack called pixel

play02:36

Adventure download it from the link

play02:38

below I'll take the green background

play02:41

image and drag it into the goo file

play02:44

system section that way it will become a

play02:47

part of our project to fill the whole

play02:50

background withd let's create our first

play02:52

Noe click on this small plus icon in the

play02:55

Sy Tab and search for texture wrecked

play02:58

node click

play03:00

create this component allows us to show

play03:03

an image on the scene simply drag this

play03:06

image from the file system to the

play03:08

texture field right here that way it

play03:11

shows up on the scene now I would like

play03:14

to resize it to the whole size of the

play03:16

screen resizing man is not a good idea

play03:19

because everything may break after the

play03:21

window resizes what we need to do is to

play03:24

click on this small green icon at the

play03:26

top and from the anchor preset select

play03:29

four wrecked to learn more about Ancor

play03:32

presets you can check out this video to

play03:35

other small tweaks first I don't like

play03:38

that this pixelated image is being

play03:40

blurred to fix that here in the

play03:42

inspector find the texture section and

play03:45

change filter to nearest much better and

play03:48

the second one instead of stretching

play03:51

this image I'd like to tile it here in

play03:54

the stretch mode select tile

play03:58

great now now let's create a ground on

play04:01

which our character will be walking for

play04:04

that we'll use a GRE til set system

play04:06

which allows us to easily paint our

play04:08

scene objects you may recognize it from

play04:11

many popular games both in the side view

play04:14

and in the top down view I'll import

play04:17

this terrain file to use it let's create

play04:19

a new note right click on the rout

play04:22

select ADD child node and search for

play04:25

tile map to start drawing tiles we need

play04:28

to do a onetime configuration ation of a

play04:30

tile set here in the inspector click on

play04:32

empty and select new tile set in this

play04:36

new window on the bottom we only need to

play04:39

drag our terrain image here click yes

play04:42

and goto will automatically split our

play04:44

tile set for us into small individual

play04:47

tiles now to draw them on the scene

play04:50

simply switch the tab on the bottom to

play04:53

tile map select tile and start dragging

play04:56

your mouse on the scene again two small

play04:59

fing to make this experience better

play05:01

first let's increase the size of our

play05:03

tiles so that everything will be bigger

play05:05

on the scene go to transform and change

play05:08

scale to three and the second one if we

play05:11

zoom in we can see the same problem with

play05:13

smoothing out pixels go to texture and

play05:17

set filter to nearest way better now is

play05:20

the time for you to become a level

play05:22

designer you can play with all the

play05:24

available tiles and tools like paint

play05:28

line or rectangle Le you can also select

play05:31

multiple Tiles at once and paint them in

play05:33

batches and when you make a mistake just

play05:36

use an eraser to cleaned now I'll take a

play05:39

second to Z my level in the meanwhile

play05:41

you can leave a like under this video if

play05:43

you're enjoying it so far also here is a

play05:46

silver badge for you you'll learn one

play05:49

more skill related to TI Maps later in

play05:51

this video all right here is what I

play05:54

created I think it will be a nice level

play05:56

to play around remember to play some

play05:58

bricks around around the scene so that

play06:00

player does not fall off the map but

play06:03

obviously something is missing our main

play06:06

character time to create one create a

play06:09

new note called character body 2D it

play06:12

should be a child of root so if you made

play06:15

the same mistake just drag it like that

play06:18

character control needs to have two

play06:20

children Sprite that will Define its

play06:23

image and a collider that will Define

play06:26

what touches the ground and collides

play06:28

with other elements on the scene let's

play06:30

start with the first one create a new

play06:32

note called Sprite 2D similarly to the

play06:36

background it also waits to add a

play06:38

texture to it I will import this ninja

play06:40

frog and set it as a Sprite texture if

play06:43

you think your character should be a bit

play06:45

bigger simply resize it and again just

play06:49

like with all other images I'll change

play06:51

the texture filter to nearest then

play06:54

collider select the character body and

play06:57

add a new note called Collision shape

play06:59

ape 2D for now it hasn't created any

play07:02

collider because we need to change a

play07:04

setting here in the inspector instead of

play07:07

empty go with the rectangle shape 2D

play07:11

that created this blue box don't worry

play07:13

it won't be visible in the game it only

play07:16

visualizes to what shape will collide

play07:18

with other objects resize on the bottom

play07:21

Edge so that it will reflect the place

play07:23

where player will be touching the ground

play07:26

colliders on the sides are not that

play07:28

important but you can simply resize them

play07:30

to the entire frog image these are the

play07:33

basics of creating Sprites good job if

play07:37

you'd like to create enemies you can do

play07:39

so by using the same node structure

play07:42

remember to experiment with different

play07:44

Collision shapes time for the very

play07:47

important skill creating subscenes our

play07:50

character is initially placed here in

play07:53

the corner obviously not an ideal place

play07:56

so I'm going to move it the problem is

play07:58

that I'm not not moving the whole parent

play08:00

but only the collider or the Sprite to

play08:03

move everything we need to create a

play08:06

subscene we can also call it a group or

play08:09

a prefab if you're coming from Unity

play08:12

right click on character body and select

play08:14

Save branch as scene now we need to set

play08:18

the location create a new folder called

play08:20

scenes rename our scene as main

play08:23

character and click save that did two

play08:27

things first we can now find our newly

play08:30

saved subscene here in the file system

play08:33

and the second our few notes have been

play08:35

combined into this one I can now freely

play08:38

move this subject with all of its nodes

play08:40

at once if you like to change anything

play08:43

for this character just double click it

play08:46

that will open a new tab with only this

play08:48

scene contents what is really important

play08:51

anything changed here will also apply to

play08:53

the main scene for example I will change

play08:56

the collider shape to capsule resize it

play08:59

a bit and press command or contrl S now

play09:02

in the main window this change is

play09:05

applied that can be even more useful for

play09:07

changing multiple subscenes at once for

play09:10

example here I have an enemy subscene

play09:13

that I placed a few times in our world

play09:16

if I open it change the rotation of the

play09:18

Sprite and save it you can now see that

play09:21

all of the enemy instances have been

play09:23

updated remember to often create

play09:26

subscenes to keep your project tidy

play09:28

let's try to play our game here in the

play09:31

top right click run project a new window

play09:35

will appear and after a second of

play09:36

loading you should see your amazing game

play09:39

for now we can't really do much our

play09:42

character is not moving let's fix that

play09:45

go to the main character scene click on

play09:47

the root node and click the small ad

play09:50

script icon we leave all of those values

play09:52

by default but let's quickly go over

play09:55

them first you select your programming

play09:57

language we'll go with g script but if

play10:00

you'd like to try out C check out my

play10:02

other video and follow the script

play10:04

alternative version shown on the screen

play10:07

then select a template goo has a

play10:10

built-in template for moving to the

play10:12

characters which we'll use for sure and

play10:15

finally set a file location and name

play10:18

it's a good practice to name it the same

play10:20

as the scene click create whoa as you

play10:23

can see goto has switched to the script

play10:26

tab if you like to go back to the editor

play10:28

you can do it here this is the template

play10:31

code for the character controller the

play10:34

good news is that it already works and

play10:36

we can test it out go to the 2D Tab and

play10:39

save the scene notice that the unsaved

play10:42

changes have the small star next to them

play10:45

press play now our game starts the main

play10:48

character starts falling and falls

play10:51

through the map what's wrong the problem

play10:54

is that our whole character has the

play10:56

Collision remember this blue box shape

play10:58

but but our ground does not the game

play11:01

simply doesn't know what to collide with

play11:04

the fix is very easy but requires a few

play11:06

clicks select the tile map in the SC tab

play11:10

then here in the inspector click on tile

play11:13

set then physics layers and click add

play11:16

element now go to this bottom section

play11:19

select tile set tab don't mistake it

play11:22

with ti map in a paint tool set paint

play11:24

properties to the physics layer and

play11:27

finally paint all the tiles that should

play11:29

collide with the player in my case all

play11:32

of the ground tiles and the rope and

play11:36

that's it now when I press play our

play11:38

character will start colliding with the

play11:40

ground perfect to control it use

play11:43

keyboard arrows and to jump press space

play11:47

congratulations on creating your first

play11:49

movement controller in goo before we'll

play11:52

move on with a nicer movement I'd like

play11:54

to quickly go back to our Sprite

play11:57

appearance currently it's just stands

play11:59

without any life we can easily fix that

play12:02

by giving it a simple idle animation go

play12:05

to the main character scene I would like

play12:08

to replace this Sprite with a node that

play12:10

enables animation right click on it and

play12:13

select change type we'd like to change

play12:16

it to the animated Sprite 2D our image

play12:20

disappeared but don't worry we'll

play12:22

quickly reverted in the inspector select

play12:25

animation and next to the Sprite frames

play12:28

click and empty and select new Sprite

play12:31

frames I'd like to use this idle

play12:33

animation frames which can be found in a

play12:36

pack import them to godo and here in the

play12:39

Sprite frames panel on the bottom click

play12:41

add frames from Sprite sheet select ID

play12:45

animation file here godo is asking us

play12:48

how we would like to split this image in

play12:51

this case I know that each frame is 32x

play12:54

32 so we can enter it here alternatively

play12:58

you can can also experiment with

play13:00

horizontal and vertical values until the

play13:02

image will be split correctly then we

play13:05

need to select all the animation frames

play13:08

simply click on the first one and drag

play13:10

your mouse along all the others that

play13:13

will create 11 frames add them now our

play13:17

animation is ready to preview it click

play13:20

this play button if the animation seems

play13:23

a bit too slow you can increase the

play13:25

frames per second value before we move

play13:28

on let's let's create two other

play13:29

animations that we'll use later on

play13:32

jumping and running for jumping that

play13:35

will be only one frame we've used before

play13:38

I will just click add frame from file

play13:40

and import this full image for running

play13:44

we'll use this Sprite sheet go ahead

play13:47

pause the video and try to add it right

play13:51

now all right here is what you need to

play13:54

do import running image in the Sprite

play13:57

frame switch to the running animation

play13:59

and press this button select the file

play14:02

slice it properly select all the frames

play14:06

preview the animation and change its

play14:08

speed to play the animation in the game

play14:11

select the default one and press the

play14:13

small button that will turn on out to

play14:16

playay on load that's it play the game

play14:19

and enjoy how our character plays the

play14:22

animation we'll work on implementing the

play14:24

other animations a bit

play14:26

later as promised let's get back to the

play14:30

scripting as you can see our movement

play14:32

works but it's quite lifeless and stiff

play14:36

time to change that switch to the script

play14:38

Tab and look at main character script it

play14:42

is very short and quite understandable

play14:44

thanks to the comments basically what's

play14:47

happening is that 60 frames per second

play14:49

we are doing three things first we check

play14:52

if our character is not touching the

play14:54

ground which means it's in the air in

play14:57

such cases we we apply a gravitational

play15:00

force that pulls it towards the ground

play15:03

it's worth noting that in gdo the y axis

play15:06

operates differently than the standard

play15:08

graph convention with positive values

play15:11

directed towards the bottom then we

play15:14

check if player is both on the floor and

play15:16

has pressed jump button in such case we

play15:19

should increase the velocity towards up

play15:22

and lastly we check if player is

play15:24

clicking either right or left button in

play15:27

such case we should change the velocity

play15:29

towards either of the sides and that's

play15:32

it pretty simple we'll have three tasks

play15:35

here flip character right or left

play15:37

depending on the movement play character

play15:40

animations depending on what's Happening

play15:42

and finally make walking and jumping a

play15:46

bit smoother and nicer to play with

play15:48

let's start with the first one if we

play15:51

take a look at our animated Sprite you

play15:53

can see that in the offset section there

play15:55

is this nice togle to flip Sprite

play15:57

graphics horizont onally we need to

play15:59

toggle it in the script depending on

play16:02

what was the last player velocity

play16:04

direction accessing nodes and their

play16:06

values in the script is very easy switch

play16:09

to the script Tab and start dragging

play16:11

Sprite to denote from the scene to code

play16:14

like that very important just before the

play16:17

mouse release hold the control key that

play16:20

will create a reference that can be used

play16:23

in different parts of the script now at

play16:25

the very end of this function we simply

play16:27

need to add two lines VAR is left that

play16:31

will be a variable that will check if

play16:33

player is facing the left or the right

play16:36

side of the screen we know that by

play16:38

checking if the velocity. x is lower

play16:42

than zero if player is facing left that

play16:46

means that we'd like to flip its image

play16:48

type Sprite Tod flipcore H which stands

play16:53

for horizontally equals is left that

play16:57

should be it Run the game and notice how

play17:00

our character is changing its size

play17:02

depending on the movement Direction next

play17:06

playing different animations now that we

play17:08

have a Sprite animator reference that

play17:11

will be very easy as a reminder we have

play17:14

three animations default jumping and

play17:18

running to change animation for example

play17:21

while jumping just type here Sprite Tod

play17:25

do animation equals jumping now when

play17:28

whenever our character is in the air the

play17:30

jumping animation starts to implement

play17:33

animations for walking and sending here

play17:36

is the code I will add at the very top

play17:38

of our function if velocity. x is

play17:42

greater than 1 or lower than minus one

play17:45

we need to cover both right and left

play17:47

movement then sprite td. animation

play17:51

equals running else sprite td. animation

play17:55

equals default remember that those

play17:58

strings need to have the exact same

play18:00

names as defined earlier now press play

play18:03

and notice how our character is nicely

play18:06

animated it even plays jump animation

play18:09

when falling off the hill and the last

play18:12

step where all the magic will happen

play18:14

will tweak some controller values first

play18:17

I like to look at this line what it does

play18:20

is that when the player stops holding

play18:22

the right or left key the character

play18:25

should gradually slow down function move

play18:28

toward takes current velocity which at

play18:31

maximum is currently 300 and brings it

play18:34

slowly back to zero using steps the

play18:38

problem is that by default the steps are

play18:40

defined using the same variable as the

play18:43

maximum speed that causes the instant

play18:46

speed drop when the key is no longer

play18:48

pressed I would suggest inputting

play18:51

something smaller here for example value

play18:53

10 that way we'll get this fun slowing

play18:57

down effect what is great about gdo is

play19:00

that you can tweak some variables

play19:02

without stopping the game for example if

play19:05

I would change that to four and save the

play19:08

player will behave as it it's on the

play19:10

eyes I think 12 is an optimal value now

play19:15

how about the other values when you

play19:17

scroll up you can see those three

play19:19

variables speed which is a max speed

play19:22

character can travel with jump velocity

play19:25

and gravity let's start with the last

play19:28

one its value is taken from the project

play19:31

settings so go to project project

play19:34

settings search for Gravity it will be

play19:37

in the physics 2D and change it to

play19:39

something bigger like

play19:42

2500 I'll increase the speed to 400 and

play19:46

the jump velocity to minus 900 remember

play19:49

minus values are going upwards after all

play19:53

of those changes press save start the

play19:55

game and try it out in in my opinion

play19:59

it's way better than what we started

play20:01

with that was a long chapter so here is

play20:04

a great reward scripting gold badge good

play20:08

job time for the last Quick addition for

play20:12

now we can only use arrows and space to

play20:14

control our character but what if you'd

play20:17

like to add other Keys when you check

play20:20

out the script you can see that we

play20:21

Define key presses using the UI accept

play20:24

left and right this is not ideal those

play20:28

mappings should be used only for the

play20:30

user interface and in fact code commands

play20:33

tell us exactly that we need to replace

play20:36

them with manually defined actions go to

play20:39

project project settings and select the

play20:42

input map tab at the top here we can

play20:45

declare actions and key mappings here

play20:48

type left and press return I will also

play20:52

add the same way right and jump under

play20:55

each of the sections we'll Define all

play20:57

keys that should trigger it click the

play21:00

plus icon next to the left action and

play21:02

press the left Arrow key it should

play21:05

automatically find the key you are

play21:07

looking for I will do it again for the a

play21:10

key to enable A and D movement finally

play21:14

if you'd like your game to support the

play21:15

GamePad you can search for left stick

play21:18

left and d-pad left I think that should

play21:22

be it now pause the video and complete

play21:25

this input map with all the remaining

play21:27

key combinations for your

play21:29

game all right here is my final

play21:32

configuration to apply it in the code

play21:34

all we need to do is to replace those UI

play21:37

something strings with jump left and

play21:41

right that's it that way you just

play21:44

completed all the budgets for this video

play21:47

congratulations if you liked this

play21:49

tutorial subscribe to Coco code and

play21:51

check my other videos as always big

play21:54

thanks to my awesome patrons that

play21:56

support this channel visit a link under

play21:59

the video to join them see you soon

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
Godot EngineGame Development2D PlatformerTutorialLevel DesignCharacter AnimationScriptingGame PhysicsInput MappingGameplay Mechanics
¿Necesitas un resumen en inglés?