Code Your First Script with Godot and GDScript

preview_player
Показать описание

In this lesson, you'll make the Godot head turn in circles and learn to listen to keyboard input to control it.

---
00:00 Intro
01:09 Setting up the project
04:10 Scripting the turning character
09:57 Moving Godot
13:18 Moving in circles
16:19 Moving with the arrow keys
20:15 Moving forward when pressing up

---
📚 THE LINKS

---
💌 JOIN US

---
📝 CC-BY LICENSE

Рекомендации по теме
Комментарии
Автор

After watching cs50 week 1 online, I can now understand what "+=" means.

a
Автор

This is a good tutorial for showing how an experienced programmer would approach this task, but I feel it doesn't quite do a great job of explaining what each of the constituent parts are. Specifically, for anyone like me who might not fully understand what that line "velocity = Vector2.UP.rotated(rotation) * speed" is doing, here's a really granular breakdown...

Basically it does a big math problem that does the following steps:
- First, it gets Vector2.UP (a pre-defined value consisting of (0, -1), which gdscript uses as a shortcut to save typing).
- Then, it uses a METHOD called "rotated" to multiply that by the argument in parentheses
- In this case, that argument is 'rotation', which is a gdscript PROPERTY which refers to the current rotation of the sprite.
- Lastly, it throws in the speed variable we created, as an overall multiplier. (The reason this is included is so we can easily adjust the movement speed by changing a single variable, up at the top of the script.)

So it does that big math problem, and then it assigns the result of all that to the "velocity" variable. That means, when it's all said and done, "velocity" holds a value that could be described as "the direction that the top of the sprite is currently facing, times a custom speed variable". You could rename this variable heading_and_speed, if that makes more sense.

The last line of code here, "position += velocity * delta" then simply tells the computer: "Change the position of this sprite by incrementing it slightly. Increment it in whatever direction the sprite's top is currently facing, and do so at the speed I've given you. Do that once per frame."

brandoncarbaugh
Автор

Weird April Fools joke, but appreciated nonetheless!

beron_the_colossus
Автор

I'm really pleased to see you guys are still at it in 2021. Your tutorials and guides have helped me a lot!

synthblade
Автор


If you have a question about this video, please write comment below the video. I'll do my best to answer them, although I can't promise to answer every question.

Gdquest
Автор

I thought this is official Godot channel because tutorials here are very well made

velderyx
Автор

If you paused the video and are looking in the comment for an explanation of why he sets angular_speed equal to PI and then still use PI instead of angular_speed in the code: he forgot, he sets it right later near the end. I found it really distracting as I was trying to figure out what I was not understanding up until he set it right.

With that said it's an excellent series so far.

SlyPearTree
Автор

I absolutely love this course! The feeing of creating something as simple as an icon rotating was so satisfying. After the video I decided to also have the icon back up when you press the page_down key and for some reason that got me really excited. Thank you so much again for creating these beginner videos to help those who'd like to get into creating videogames!

SiofraTural
Автор

how does the rotation and position works? why do we need to keep them in the code?

EDIT: ctrl+clicked the thing and it came up. rotation and position is a part of Node2D thingy. I get it now. But please do correct me if I'm wrong :D

michaelrumondor
Автор

I'm at around 9:52 when you first test the rotation script but my sprite instead of spinning in place, is moving around the screen, almost orbiting something in the top left corner extremely quickly? my code looks like this:

extends Sprite

var angular_speed = PI

func _process(delta):
rotation += angular_speed * delta

(also its just the sprite node with the icon.png as the texture)

Edit: i have no clue what i did but i re-wrote it the exact same way with the exact same code and it worked..

Boxolotl
Автор

This language is brain dead easy and I love it. Much nicer to use that C++, and it is great that you can write it in the engine and it recognizes what you type with no fuss. I am happy.

drakorez
Автор

Great tutorial, friend. After finishing it, I messed around with the code a bit and figured out how to make the Godot icon slow to a stop after letting go, like it's an ice level or something. Really fun.

hatandhoodie_
Автор

This is very late, but for those who may be confused by the portion at 16:00,
Up is relative to the position of the node, not the scene itself. So since the Godot head started upright, 'up' is always toward the top of its head.

aden
Автор

Super fun tutorial! You slowly helped us build this little movement game, by showing us the building blocks of it. I felt immense gratification when I paused the video, and realized I could uncomment the previously commented movement code and added another if statement to detect an up press :) keep up the great work!

sparklyspartan
Автор

GDScript is a lot easier than C++ lol

also if you wanna do full arrow keys movement just add under Var velocity :
if
velocity = * speed

HalfAsleepSam
Автор

Did this just drop today? what a perfect day to start learning Godot. 👍📚

Iglum
Автор

@GDQuest This is probably the most user friendly programming tutorial ever made. You explain e.v.e.r.y.t.h.i.n.g in details, which helps a lot to understand this seemingly non-sensical jargon. Congratulations, this is very valuable! And thanks for making this. :)

philippedcote
Автор

I've hit summer vacation and decided to start learning Godot as my first not visual scripting experience. This series has been super helpful so far, and I decided to go one step further and try to make the godot icon move backwards at half the speed. Figured it out pretty easily; feel weirdly proud on that one

averyshurts
Автор

Wow, I really was very hesitant to use GDScript, but it actually looks really pleasant to work with :)

edgarsketches
Автор

Super helpful, thank you guys so much for this tutorial series!

Karce