Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.
Are you fine with me finding other ways to do some of the things?bogus-craneI used the code
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
func _process(delta: float) -> void:
var direction := Vector2(0, 0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1.0:
direction = direction.normalized()
velocity = direction * max_speed
position += velocity * delta
if direction != Vector2(0, 0):
rotation = velocity.angle()
```
to do this.27Jun. 27, 2024
My (newbie) code comments to anyone who may have issuesNekrys```gdscript
extends Sprite2D
var max_speed := 600.0 # ':=' defines automaticly the var type
var velocity := Vector2(0,0)
func _process(delta: float) -> void:
#defines the inputs up, down, left and right on the vector 'direction' (split between the X and Y axels)
var direction := Vector2(0,0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up","move_down")
#Gets the length of the vector direction (by using .length) and if it is bigger then 1
#then normalizes it (divides its value by itself to get a final value of 1)
#this allows for diagonals not be faster than going up, down, left and right
if direction.length() > 1.0:
direction = direction.normalized()
#[vetor] velocidade = [vector]direção * max speed
velocity = direction * max_speed
#moves the character each frame.
#Speed is a constant that is part of the velocity variable (direction* max_speed) wich then gets multiplied by delta to calculate the amount moved in a single frame
position += velocity * delta
#keeps the sprite looking to the last direction
if direction.length() > 0.0:
rotation = velocity.angle()
```24Apr. 21, 2024
End direction when moving diagonallyHilton184When moving diagonally and then stopping, the ship typically does not finish facing diagonally. For example, when moving towards the top right (holding down W and D) -> ship moves diagonally. Release the keys and the ship will end up facing either UP or RIGHT. This is unless you release W and D at exactly the same time. If they are released even slightly apart, the ship won't finish facing diagonally, and it looks really jerky / not natural. How can this be fixed?44Feb. 16, 2024
Having trouble understanding how the code makes the ship retain its anglefamiliar-camelif direction.length() > 0.0:
>| rotation = velocityangle()
Im not really sure how this causes the ship to retain the angle. could someone please elaborate?
23Apr. 15, 2024
Making movement smoother for Controller?HollowWhen testing with a controller joystick I noticed that the movement feels very stiff (due to the limit to 8 directions I presume). I was wondering how it could be made that the ship more smoothly transitions between directions / that it is not limited to the 8 directions?32Feb. 13, 2024
Why does the ship move faster when going diagonally?front-pantherI'm completely new to coding, and the part I'm struggling to comprehend is why does it become 40% faster. I'm not really understanding the math here. I don't think it's really important to know as of right now, but I'm really curious. 141Feb. 15, 2024
What is the purpose of :=mrpizzahunterFor example in:
`var velocity := Vector2(0, 0)`
Why not just use the = symbol?61Feb. 05, 2024
Controller joystick + diagonal speedmiiaSo when using WASD, not normalizing the vector is indeed faster. But when using a joystick on my PS5 controller, diagonal movement feels much slower. Why would this be?61Feb. 04, 2024
L3. curious questionNormalAs stated in this lesson that the 'get axis' makes the value between -1 and 1. The decimal values between -1 and 1 are for controllers, right? like the pressure sensitive triggers 20Nov. 13, 2024
Course compatible using C# instead of GDScriptprobable-antNot a question, but for anyone out here curious: If you want to use C# instead of GDScript and wonder if the Plugin will still recognize it: Yes, it does. I've passed the test using C#, even with a little different approach and got my little dopamine kick with the green checkmarks.
Just keep in mind to use the exact var names like in the course. I named max_speed for example maxSpeed and it threw me an error, but worked, as soon as I used the right name.30Nov. 06, 2024
L3.P1 and L3.P2. Code is corrrect and ship matches referances but test still failsknotty-wormSo I'm using the the code blow. on P1 reference will move and I can control the reference on the right but the left one won't move at all so test fail.
For P2 both left and right are in perfect sync with the same code below but the test again fail. feels like hitting some kind of bug. testing the code manually shows that it meets all the requirements
I'm on linux using version 0.2 of the gdquest pratice pluging. output window reports that the version godot you shipped in the zipfile is v4.3.stable.official.77dcf97d8
only none standar thing I have is that I have a vim keybinds plugging because after more then 10 years of using vim moving in the editor with arrows feel so wrong
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
var direction := Vector2(0, 0)
func _process(delta: float) -> void:
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
# If we don't do this and the player moves diagonally, they will move 40%
# faster than normal.
if direction.length() > 1.0:
direction = direction.normalized()
velocity = direction * max_speed
position += velocity * delta
if direction != Vector2(0, 0):
rotation = velocity.angle()
```50Nov. 05, 2024
Error in L3.P2violet-shrewI copied and pasted the solution for L3.P2 into character_diagonals and yet it fails the "direction vector is never longer than 1" check.
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
# Once again, the direction variable is outside the _process() function so the
# practice testing code can read its value.
var direction := Vector2(0, 0)
func _process(delta: float) -> void:
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
# The character is way too fast, but only when moving diagonally!
# Add code to prevent that.
if direction.length() > 1.0: #
direction = direction.normalized() #
velocity = direction * max_speed
position += velocity * delta
if velocity.length() > 0.0:
rotation = velocity.angle()
```10Nov. 02, 2024
I can't open L3.P1well-off-apeWhen I try to start the practice, it just opens the same code I was working on. Can you help me?10Oct. 30, 2024
L3.P2 エラーbeloved-porcupineHello, I got following error after running L2.P2 test
> Direction vector is never longer than 1
> Velocity vector is never longer than max speed
I tried to fix the test.gd line #74 as previous post, but It didn't work
My code is below:
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
# For this practice, we moved the direction vector outside the _process() function.
# This allows the interactive practice to read its value and test if your code passes!
# You can access and change the direction variable inside the _process() function as you did in the lesson.
func _process(delta: float) -> void:
# The direction is always equal to Vector2(0, 0)! Add code to remedy that.
var direction := Vector2(0, 0)
direction.x = Input.get_axis("move_left","move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1.0:
direction = direction.normalized()
velocity = direction * max_speed
position += velocity * delta
if velocity.length() > 0.0:
rotation = velocity.angle()
```20Oct. 20, 2024
test error in L3.P2orderly-woodcockwith this code:
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
# ...
var direction := Vector2(0, 0)
func _process(delta: float) -> void:
# The direction is always equal to Vector2(0, 0)! Add code to remedy that.
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1.0:
direction = direction.normalized()
velocity = direction * max_speed
position += velocity * delta
if velocity.length() > 0.0:
rotation = velocity.angle()
```
I get "Direction vector is never longer than 1" error during the testing, which is not true as direction is normalized. I tried also with Input.get_vector, same error.
30Oct. 15, 2024
Wasn't able to get L3 P2 to work despite directly copying the answer from the soloutions pagedftgyhgjgyfHey, I tried solving the practice and was pretty sure I got it, but i kept getting an error inside the program that I had to normalize the Vector, despite having done so. I decided to check the soloutions page and directly copied it (to try and figure out what i'm missing) in but I still got the error [https://imgur.com/ctd7NxQ](https://imgur.com/ctd7NxQ) 90Oct. 11, 2024
The line "With this code change, run the scene again, and now the ship's speed should be consistent even when moving diagonally." doesn't seem to fit where it's placed.dftgyhgjgyfIt's placed right after fixing the rotation, not after fixing the extra speed with diagonal movement which is weird as the rotation issue affects all movement, not just diagonal. It seems as if it was moved from the end of "Normalizing the vector" section. Of course I could be completely wrong but just letting you know in case the placement is unintentional10Oct. 11, 2024
Doing Input differentlySkits```gdscript
Some of the things I picked up before buying this gamedev from zero.
Vector2.ZERO is the same as Vector2(0, 0)
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2.ZERO
func _process(delta: float) -> void:
var direction := Vector2.ZERO
direction.x = -Input.get_action_strength("move_left") + Input.get_action_strength("move_right")
direction.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
if direction.length() > 1.0:
direction = direction.normalized()
velocity = direction * max_speed
position += velocity * delta
#position += speed * delta
if direction.length() > 0.0:
rotation = velocity.angle()
```40Oct. 07, 2024
Bug: Godot freezes when clicking outside Event Configuration windowCM66When entering the input maps, if you click the plus sign to add event to an action, a window pops up to listen for input (Event Configuration). If you click outside of this window, the window will close and Godot will freeze. You can't close the input map window or Godot itself. I had to use Task Manager to close Godot.
This only happens with the Godot application that comes with the files you download for this course. If you do this using the Godot application you download from the Godot website, the window will stay open.
I was confused why this was happening until I realized that I was double clicking the add event + button.
Using Windows 10 on a desktop PC.30Oct. 02, 2024
Sample code fails test for L3.P2CarobertI had what I thought was a correct answer for L3.P2 but it kept failing the tests, so I copied the sample code, and it is asserting that the unit tests are failing. Any thoughts on what is happening?40Sep. 24, 2024
Why "direction.x/y" are not var?united-armadilloHi, I noticed that we first declare the variable "direction", then under that we have direction.x and direction.y that are equals to the input...
Here's the code
var direction := Vector2(0, 0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down").
it's confusing to me that the direction.x and .y are not declared as variables. I guess this has to do with the "." Followed by the x and y which I suppose are the arguments of Vector2? Can you explain this concept further?20Sep. 22, 2024
Does the order of the arguments in "get_axis()" matter?onemoreturn_I wrote the arguments of get_axis in reverse order ("move_right", "move_left") and it gave me an error in the practice.
Is it because it's comparing against the result of the activity or does the order really matter in reality?
```gdscript
func _process(delta: float) -> void:
direction.x = Input.get_axis("move_right", "move_left")
direction.y = Input.get_axis("move_up", "move_down")
```10Sep. 20, 2024
Sprite facing in the wrong direction after diagonal movementbrief-whaleI have the same problem that after a diagonal move the sprite looks right left up or down and not diagonally. When I move it, it points in the right direction, but when I stop it only points in one of the 4 directions mentioned above. one of the people here in the comments was confused and me too. it would be cool if you could add a small fix. Thanks :)10Sep. 04, 2024
The L3.P2 practice crashesrowdy-rhinocerosI ran the L3.P2 practice with my code and it crashed, Invalid get index "direction" (on base "Sprite2D(character_diagonals.gd)"). turned out, after a long time speculation over what was wrong, that I had the if direction.length() > 1 and not 1.0 FYI20Aug. 23, 2024
Does is matter where we normalisekaku9879i did the code and also a side project both normalising the direction at the very end and it works fine but in the practice if you do this is counts it as wrong and only works if i put it after the inputs but then i went back to my side project and the main ship script and tried to put it before the inputs it then didn't normalise? just wanted to understand 20Aug. 19, 2024
My max_speed is 10 times slowerblushing-squidI have to make my max_speed := 6000.0 to make it move like the example in the tutorial. I'm using a relatively powerful PC so I don't think it's the PC's problem.
I also tried out Animation the other day (unrelated to this tutorial), it looked normal inside the editor but once I run the scene the animation becomes significantly slower.
Does anyone know what could be the reason ?30Aug. 17, 2024
Player's movement direction: Input.get_action_strengthboaroHey guys! Congratulations on the amazing course methodology, it's really great.
I have a question about **Input.get_action_strength()**, I saw that you have used it in the the **CharacterBody2D** movement on the **Get to Know Godot** project. But you didn't motioned it in the **M4.L3**.
Do you mind to explain the diference (or pros and cons) of using it over **Input.get_vector()** and **Input.get_axis()**.
Thank you!10Aug. 16, 2024
Question about direction being defined within process functionsuperior-aardvarkI was having issues getting my code to run with the direction variable being defined in the process function, so I moved it outside the process function and that fixed my issue. My question is: is there any way writing it like this would work? Correct me if I'm wrong, but wouldn't defining a variable with a value of 0 inside the process function create and set that variable equal to 0 every frame, making it useless if it constantly needs to change?40Aug. 14, 2024
Is it safe to compare ints and floats?raincloudIn lines 14 and 20 of the reference code, is it important that `direction.length()` is compared with the floats `1.0` and `0.0` instead of ints? I had instead written `if direction.length() > 0:` for line 20, for example, and it worked as expected. Is that a habit that could cause problems for me down the road? In the code docs, I see that `length()` always returns a float, so is it best practice to keep types consistent when using comparison operators?20Aug. 12, 2024
Flip the spriteMaziHi!
Just a question. If I saw correct when we press the left or right, up or down the ship sprite is just flipping (veritcally, horizontally) but to the opposite side. It is not a problem if I use this sprite because the upper and the down side are the same so I can never recognize it but I tried the code with Godot logo. :)
Could you please tell me a solution for this? I tried a few things what i found on the internet but i am a beginner and I don't want to learn bad things and of course I had no success. :)
Thanky you!40Aug. 11, 2024
I forgot something on one of my questions.dofudengamesFor my suggestion, i meant like the onion peel of the ship30Aug. 04, 2024
Getting Errors after a Blue Screenpossible-humanHi there! Was enjoying my time running through the practices until i experienced a blue screen of death while running "Speeding in Diagonals".
After getting back in, I'm getting the following errors:
scene/resources/resource_format_text.cpp:1047 - user://progress_v2.tres:1 - Parse Error:
Failed loading resource: user://progress_v2.tres. Make sure resources have been imported by opening the project in the editor at least once.
Error loading resource: 'user://progress_v2.tres'.
res://addons/gdpractice/ui/ui_selectable_practice.gd:92 - Invalid get index 'state' (on base: 'null instance').
res://addons/gdpractice/ui/ui_selectable_practice.gd:92 - Invalid get index 'state' (on base: 'null instance').
res://addons/gdpractice/ui/ui_selectable_practice.gd:92 - Invalid get index 'state' (on base: 'null instance').
res://addons/gdpractice/ui/ui_selectable_practice.gd:92 - Invalid get index 'state' (on base: 'null instance').
res://addons/gdpractice/ui/ui_selectable_practice.gd:92 - Invalid get index 'state' (on base: 'null instance').
Now the practices don't work :( pls help! I tried downloading fresh, extracting to different locations, but no improvement.20Aug. 01, 2024
Dark modemiserly-dugongI don't know if you plan on having a dark mode one day but it would be lovely, having to switch between Godot's default dark theme and the stark white website is a bit of a pain. Thank you so much for everything, the rest of the user experience is amazing.40Jul. 24, 2024
Trouble with the GD praticeskarlscodingWhen I press run it opens the game but it doesn't work and it goes to a script called test. 10Jul. 23, 2024
L3. - Value types in the code questionMatejHello, is there a reason why some of the values are float type?
```gdscript
var max_speed := 600.0 # Could I type 600 instead without causing
# any Issues for this specific project?
# Same question here, would using an integer be ok for this project?
if direction.length() > 1: # <-- Good? Bad? Depends?
direction = direction.normalized()
# Instead of (as per the project guide):
if direction.length() > 1.0:
direction = direction.normalized()
```
Expanding on the .length() - Is the reason we type '#... direction.length() > 1.0' instead of '#... direction.length() > 1' just because the .length() function returns a float value (as in good practice/convention)? Or could using an integer cause some issues later on?20Jul. 21, 2024
Velocity Vector Issue in L3.P2complex-antI had no issues with the previous practice but I seem to be missing something in Practice 2. It says there is a case where the length of the velocity vector was greater than the max speed and asks if I normalized the direction vector which I though I did.
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
# Once again, the direction variable is outside the _process() function so the
# practice testing code can read its value.
var direction := Vector2(0, 0)
func _process(delta: float) -> void:
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
# The character is way too fast, but only when moving diagonally!
# Add code to prevent that.
velocity = direction * max_speed
position += velocity * delta
if velocity.length() > 0.0:
rotation = velocity.angle()
if direction.length() > 1.0:
direction = direction.normalized()
```
I'm not sure what to do to fix this.80Jul. 17, 2024
Game Freezes/ not smoothfixed-bearI was wondering if the tests are meant to be smooth as it seems like my Godot engine freezes every 1-2 seconds. Im not sure how I can share a video of the screen but the "gameplay" is not smooth even if the code is identical to the one provided in this course.
It does not seem to be an issue with the inputs as well as just setting the position += velocity * delta (ie code from last lesson) still gets stuck/freezes every 1-2 seconds60Jun. 25, 2024
Input mapping flips if not in specific orderPixelbladeI noticed that the directional input along the x and y axis depends on the order that the input mapping appears in the code. What am I missing? The order in which input mapping names are referenced in code should not matter!
**Movement input is flipped**
If I push the key to move to the right, the ship moves left. If push the key to move up, the ship moves down. etc.
```gdscript
func _process(delta: float) -> void:
var direction: Vector2 = Vector2(0,0)
direction.x = Input.get_axis("move_right", "move_left")
direction.y = Input.get_axis("move_down", "move_up")
```
**Movement input works as expected**
The input keys move the ship as expected. Key to move right, makes the ship move right, etc.
```gdscript
func _process(delta: float) -> void:
var direction: Vector2 = Vector2(0,0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
```
20Jun. 14, 2024
About the final code in this lessonHazlarHello,
```gdscript
extends Sprite2D
var velocity := Vector2(0, 0)
var max_speed: float = 300.0
var direction: Vector2 = Vector2(0, 0)
func _process(delta: float) -> void:
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1.0:
direction = direction.normalized()
velocity = direction * max_speed
position += velocity * delta
if direction.length() > 0.0:
rotation = velocity.angle()
```
In this course, we deconstructed the variable velocity to make it hollow and re-fill it with its twin (`var direction`) (because it is also a vector) then its displacement coefficient (`var max_speed`).
I therefore notice that modifying the direction structure is implicitly modifying that of velocity (or the sprite?).
Because in the examples of the ship, once we normalize the direction structure then another time the final `velocity` variable. But from what I understand the two variables for me are 'twins'. So what motivates choosing one more than the other? Should we intellectualize this because it presents notable differences later, or act and think afterwards?
Thank you in advance10Jun. 12, 2024
Several questions about pixel and diagonal displacementHazlarHello,
if 1 pixel is 1 cm on each side, and my movement step is 1 cm. if I go diagonally I would not reach the end with this single step, I will still need about 0.4 cm so what does the computer do if the movement is not standardized? the player moves forward again with a new step of 1 cm to finish his race regardless, thus passing the opposite corner?
If yes the player will have traveled 2 cm diagonally instead of 1.4 so will have bitten 0.6 cm more so covered 60% of additional ground but you say 40% and that is where I would like to have details.
I guess the player doesn't actually walk inside the square that represents the pixel, he follows sub-grids of coordinates while crab walking? once **__** and once **|** ?
Thanks in advance30Jun. 09, 2024
Why do we need parenthesis after for exemple direction.length()ChanclinkI did not clicked before but I struggled with a stupid error because I did not put the parenthesis after direction.length() because I don't understand why we need them ?
For me parenthesis are for us to enter parameters for functions, am I wrong ?
or is it that the variable direction here, since it's a Vector2 type, is considered an "object" and then we need parenthesis because .length is actually a function ?30Jun. 03, 2024
Jittering in fullscreen modeadventurous-wildcatHello, on my Dell 60Hz, 3440x1440, I got jittering, when trying the game in fullscreen mode. It's fine when I play in windowed mode. What I found was, when I disabled the V-Snyc Mode in the Project Settings, the jittering would stop. Why is that? More importantly, disabling V-Sync shouldn't a favorable solution. Won't fast paced games need V-Sync? Also the players may want an option to turn it on on their side... it seems like jittering and stuttering is a common problem in Godot, from what I have read. By the way, this was not a problem with the sample game in the Tours. Basically I am worried about the performance.10Jun. 01, 2024
Can we leave out velocity? Why not?kindly-gerbil```gdscript
extends Sprite2D
var max_speed := 300
func _process(delta: float) -> void:
var direction := Vector2(0, 0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1:
direction = direction.normalized()
position += direction * max_speed * delta
if direction.length() > 0.0:
rotation = direction.angle()
```10May. 30, 2024
Question about func _input()Lucas PscheidtWhy is it better to set the direction inside _process function instead of using dedicated _input function to receive the information when the movement inputs get pressed? I don't understand when to use this function instead of checking for input in _process.10May. 23, 2024
Does the 'var direction' line have to be in the function?nasty-beeCan't we just put line 8 "var_direction := Vector 2(0, 0)" outside of the function with the other variables? In the challenge that's where it is and it doesn't seem to make a difference. Thanks!10May. 16, 2024
GD Quest issuecomplex-hornetIf I'm following along with the character_input.tscn instructions and try and run the scene, it instead runs the GD quest window and crashes the editor. The only fix I have found is to disable the GD quest plugin until I'm ready for the challenges.10May. 09, 2024
Error: Input Map Action does not existample-troutCan someone help me trouble shoot? I am getting an error that reads "Invaled get Index 'direction' (on base: 'Sprite2D (character_input.gd')
When I press play through godot I can use the keyboard to move my character, but when I press run through the tutorial it shuts down my trial and gives me this error.30May. 08, 2024
Invalid path in L3.P2big nemoIt looks like the path to the practice solutions changed but at least one of the files didn't get updated accordingly. Prior to changing this file reference the L3.P2 practice just freezes up and throws a file not found error in the debugger.
L3.P2/character_diagonals.tscn contains the line:
`[ext_resource type="Script" path="res://practice_solutions/L3.P2.character_diagonals/character_diagonals.gd" id="2_mon8h"]`
It should be:
`[ext_resource type="Script" path="res://addons/gdquest_practice_framework/practice_solutions/L3.P2.character_diagonals/character_diagonals.gd" id="2_mon8h"]`40Apr. 30, 2024
Bug: When trying to run test, const Utils is already in scopeOwl KnightHad to change the line to be a comment for the tests to run. Not sure why no one else seems to be having the same issue. #const Utils := preload("res://addons/gdquest_practice_framework/utils.gd")
Specific to L3.p1 + p2 so far40Apr. 29, 2024
My character is not moving! issuealanlovesgameswhen playing the test scene, it says the godot project is missing the input actions but i put them in and am moving the bullet around, am i missing something?40Apr. 28, 2024
Bug if you move direction var inside _process func in character_inputandrea-putortiAfter I completed the practice "My character is not moving!", I tried moving this line inside the function _process, just to test more:
```gdscript
var direction := Vector2(0, 0)
```
When I pressed F6 to run the scene, it gave me an error of course, but also showed me a whole different sheet of code, which I believe is the backend test code (I can send screenshots if needed).
Even if you press CTRL+Z it won't cancel the action done, the only way to fix it is to switch the scene to another and get back to find the code as you edited it, then you can CTRL+Z.10Apr. 16, 2024
Understanding "rotation = velocity.angle()"leafWhat exactly is happening when we use **.angle()** on our **velocity** variable? I understand that with the line of code we are setting the **rotation** property of the ship to be in the direction of our **velocity** variable. I guess where I am confused is, what exactly is **.angle()** doing here? Isn't the value of **velocity** already being returned as a negative or positive vector value based on our **direction** and **max_speed** variables?10Apr. 15, 2024
L3.P1 Practice FailingleafThe character_input.gd script for the practice test L3.P1 I have entered is coming back as failed, when I run the test, the players are moving in the same direction, and in sync, but there is a slight difference in position of the opaque player and the other. What am I missing here?
This is what I am using:
```gdscript
extends Sprite2D
var max_speed := 600.0
var velocity := Vector2(0, 0)
# For this practice, we moved the direction vector outside the _process() function.
# This allows the interactive practice to read its value and test if your code passes!
# You can access and change the direction variable inside the _process() function as you did in the lesson.
var direction := Vector2(0, 0)
func _process(delta: float) -> void:
# The direction is always equal to Vector2(0, 0)! Add code to remedy that.
velocity = direction * max_speed
position += velocity * delta
if direction.length() > 1.0:
direction.normalized()
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if velocity.length() > 0.0:
rotation = velocity.angle()
```30Apr. 11, 2024
Diff, New, and Old - Heads up! (also, typos)leafHey all and good day to you; I hope you are making it through and are learning well!
I have been reading through this step by step, very carefully and slowly, and I noticed there may be a lack of instruction. Correct me if I am wrong (and please do), I have not have seen anything stating what *"**Diff**, **New**, and **Old**"* do in the examples. I think I understand them now -
**Diff**: Shows both code examples side by side showing the difference.
**New**: Shows the line of code as it should be after the changes.
**Old**: Showing the old line of code that was replaced.
- It caused minor confusion for me, and I am lucky I caught on to what was happening after having a minor bit of trouble with a typo of the word "length" (be careful with misspelling words like this, easy to miss; luckily, misspelling it lead me to understand what these example features likely do.)10Apr. 11, 2024
Small typo?A_Room_With_A_MooseUnless I'm reading this incorrectly, there seems to be a typo in the "Detecting player input" section.
[https://school.gdquest.com/courses/learn_2d_gamedev_godot_4/to_space_and_beyond/taking_control#detecting-player-input](https://school.gdquest.com/courses/learn_2d_gamedev_godot_4/to_space_and_beyond/taking_control#detecting-player-input)
Paragraph 1, sentence 2:
"It will represent the direction in which the player we want the ship to move."
I presume it's meant to read "It will represent the direction in which we want the ship to move," or "It will represent the direction in which the player wants the ship to move," correct?10Apr. 07, 2024
How does vector normalization work?woeful-llamaI think I'm digging a bit too deep here, but just can't wrap my head around the way the division of the **Vector2(1.0, -1.0)** by its length provides us with the "correct" direction vector whose length is lowered to **1.0**.
Using a formula from SG1 in this module, I've tried doing the division manually like so:
*Vector 2 (1.0 ÷ length, -1.0 ÷ length)* where *length=1.41421356237*.
But I'm left with a result of Vector2(0.70710678118, -0.70710678118). Its length is almost 1, but not exactly. So, am I correct in thinking that inputting this:
`if direction.length() > 1.0:`
`direction = direction.normalized()`
Doesn't actually change the fact that the ship has a different velocity when it moves diagonally. It's just that the difference between the straight and diagonal velocity becomes visually unnoticeable, right?20Apr. 03, 2024
L3.P2 CompletionCheck Error?NickGodot 4.2.1
When normalizing vector direction in velocity definition string
velocity = direction.normalized() * max_speed
"Direction length is never longer than 1" check remains unmet,
hinting on normalizing direction.
I know code enough to override direction string to be:
direction = Vector2(Input.get_axis("move_left", "move_right"),Input.get_axis("move_up", "move_down")).normalized()
Then it works. But isn't it identical? Or is there an error in the conditions?10Apr. 02, 2024
Suggestion on implementation of _processzshazzOne improvement I'd suggest is using `get_vector` over the `get_axis` + `normalized` approach. It behaves much more predictably for me using a joystick (in particular, the dead zone is a circle rather than a square), and it automatically normalizes the direction for you, saving you from having to do that step. That's also the [recommended approach](https://docs.godotengine.org/en/stable/tutorials/inputs/controllers_gamepads_joysticks.html#which-input-singleton-method-should-i-use) by Godot for handling analog-aware movement.60Apr. 01, 2024
Typo in "Detecting player input"Adimo37Hello, I think there is a typo in the second paragraph:
Define a new variable named direction at the top of the _process() function. It will represent the direction in which the player we want the ship to move.
It should be "It will represent the direction in which we want the ship to move."10Mar. 29, 2024
Setting direction inside of _process in Practice?machinemanFor some reason, in the first practice, my code doesn't work if I add the
```gdscript
var direction: Vector2 = Vector2(0, 0)
```
to the `_process` function.
If I leave it out, the test is passed.
In some sense I think I understand why it works when it's not in there... but that makes me question why the "correct" solution has it in there?50Mar. 24, 2024
Slow speed moving diagonally with control stickSamukaveraI was getting slow speed when moving diagonally using the control stick in my controller.
To solve this I used Input.get_vector instead of Input.get_axis10Mar. 23, 2024
Section needs clarity444bIn the section "Calculating the movement Direction":
There is a statement that we can decompose the velocity into two values: Direction and speed
`We can decompose the velocity into two values:`
1. `The direction is a Vector2 value with a maximum length of one.`
2. `The speed is a decimal number representing the velocity vector's desired length.`
Issue: Is it not clear why this is the case or why we can decompose it into two values.
This section needs a bit of structure and elaboration in order to be clear.
Please elaborate.
30Mar. 17, 2024
Why is it necessary to initialize the direction variable every frame?Slate Jamesis there a reason to keep line 8 `var direction := Vector2(0, 0)` in the function? Why can't it be initialized in line 5, outside of the function?20Mar. 14, 2024
Had to swap move_up and move_down in L3.P1splendid-albatrossIn L3.P1 I was getting a fail due to the up and down movement not working. I switched the up and down callouts in the Input.get_axis() and I got success. The input keys are correct, so I'm not sure why the order should matter.20Mar. 14, 2024
"Editor Settings -> Shortcuts" weird behaviour?Hermundure
I toyed around with different methods to move the ship and recognized something I do not understand.
If I use our created inputs in the input map, like shown in the code below, the printed velocity values are as expected:
```gdscript
func _process(delta: float) -> void:
velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down")
position += velocity * speed * delta
print(velocity)
```
Printed values:
-1,0
1,0
0,-1
0,1
But if I exchange the input arguments with the ones that come with Godot (editor settings -> shortcuts) I get weird results:
```gdscript
func _process(delta: float) -> void:
velocity = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
position += velocity * speed * delta
print(velocity)
```
Printed values:
-0.997638, 0.068685
0.718478, 0.057677
-0.133595, -0.873792
-0.140943, 0.990018
The ship also does not move in a straight line anymore (thats how I discovered this weird behaviour). I already downloaded the 4.3 dev version of GD but it behaves the same, even in the other version. Why is that?
40Mar. 11, 2024
How 40% longer?datiswous> But if we simultaneously press right and up, the calls to `Input.get_axis()` give us a value of `1.0` for x axis and `-1.0` for the y axis of our `direction` vector. In that case, the direction vector is about 40% longer.
Why is it 40% longer? I don't understand where the number 40 comes from.60Mar. 11, 2024
Please make title stickygnomerunnerHi
Suggestion for UX improvement.
When a question is clicked, the sidebar has 2 titles and it feels like the top one was expected to be sticky but it is not.
Redundant title can also be removed.
10Mar. 10, 2024
Typo "Congradulation"NOAVGCNoticed that when successfully running practice code, you receive the message "Congradulation". It should be Congratulation10Mar. 06, 2024
Error when trying to start L3.P1CerealWhen I try to start L3.P1, it says: "Invalid get index 'direction' (on base: 'Sprite2D (character_input.gd)')." and opens up a script for test.gd in character_input.gd. It then points me to line 49 of test.gd which reads:
data.practice_direction = _practice.direction
However, it does actually open up the test menu but immediately freezes indefinitely. 50Mar. 06, 2024
Add example for `Turning the ship only when moving`shouplesThe purpose of this section wasn't very clear -- it may be helpful to add a before/after example, like "notice if you move the ship around, its rotation resets back to facing toward the right even if the ship stopped while facing up/down/left" before adding the `if direction.length() > 0.0` condition.30Mar. 02, 2024
Stutter with this movement codebc likes youSetup: Godot's run window plays on my 2nd monitor (Dell U2415, 1200 x 1920, 60hz, oriented vertically).
Issue: I get movement stutter every second or so. It's less so on my main monitor.
I have another top-down project that uses the following code and I get no stutter.
`if Input.is_action_pressed("right"):`
` velocity.x += 1`
Totally possible it's my machine but I thought I'd give you a heads up.30Feb. 27, 2024
Format the codezemyIs there any shortcut that format the code like in others IDEs?10Feb. 24, 2024
Opinion on Input.get_axis() vs Input.get_vector()PattyI noticed that Input.get_vector() works similarly to get_axis(), but it also normalizes the vector and keeps getting the direction in one method. Is one better in this case or is it just preference?
Also, really liking the course so far!20Feb. 20, 2024
diagonal speed if statement doesn't work on L3.P1 lucky-locustit works on L3.P2, so no worries, but I did it in p1 without knowing I had it in the next text but when pressing play the bullet still goest faster when facing diagonally. Thanks!10Feb. 19, 2024
Why check for length prior to normalizationlovely-foxInstead of normalizing the direction vector when it's length is greater than 1.0 why not normalize the vector all the time. This shortens our code and removes the computation of the "if" statement.20Feb. 11, 2024
L3.P1 and L3.P2 pass without any changeAdrOn Linux/Godot 4.2.1 stable (as provided), the plugin shows the L3.P1 *My character is not moving* and L3.P2 *Speeding in diagonals* as passed without having the user to have to do anything.20Feb. 10, 2024
velocity > 0 in L3.P2Trifidein the lesson, we set up the rotation lock when not moving by checking the direction variable, but in the practice the line check the velocity instead, is it another way to lock the rotation or is it a typo?40Feb. 09, 2024
Typo in the paragraph "Why does the ship move faster when going diagonally?AlcedoHi, I think there is a typo in the text above the second screen of the paragraph.
If we simultaneously press right and up, `Input.get_axis()` should return 1.0 for the x and -1.0 for the y.10Feb. 05, 2024
Typo in the folder and file names for practice L3.P2iDieThere is a typo in the folder and file names for practice L3.P2.
It should be diagonals instead of diagionals.
I am using the "version" learn-2d-gamedev-projects-0.1.0-windows.zip10Feb. 04, 2024
question on Complete code line 20Adamsapwhy is line 20 of the complete code on browser using direction instead of velocity?
Are we not supposed to be doing this if the player is moving only?
I used velocity as we are only supposed to rotate if we are moving.40Feb. 03, 2024
Lesson Q&A
Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.