Looks like you're not logged in

Login or Register to continue

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.

  • Sprite turns right when I don't press any arrow on keyboardAlcedoHi, after the completion of the script when I left the arrow keys on the keyboard, the sprite turns on the right side but keeping the y position. I think this is due to the last line of code `_skin.flip_h = sign(direction.x) < 0.0`. To prevent this behavior I added an If to check if there is no direction input. So my last lines of code are `if direction.x != 0.0:` ` _skin.flip_h = sign(direction.x) < 0.0` Do you guys think there is a better way to prevent this behavior? 1 8 Aug. 21, 2024
  • About the Dictionary techniqueWatchinofoyeAt the beginning of the lesson, you say "I will run you through different techniques to do that, starting with simple if and elif statements and ***moving on to a more advanced technique using a dictionary***." Guess it have been missed because it does not appear in the lesson. I presume it would be something where we have a dictionary using Vector directions as keys and textures as values? Something like this : ```gdscript var directions = { Vector2.LEFT: RUNNER_RIGHT, Vector2.RIGHT: RUNNER_RIGHT, Vector2.UP: RUNNER_UP, Vector2.DOWN: RUNNER_DOWN, UP_LEFT: RUNNER_UP_RIGHT, UP_RIGHT: RUNNER_UP_RIGHT, DOWN_LEFT: RUNNER_DOWN_RIGHT, DOWN_RIGHT: RUNNER_DOWN_RIGHT, } ``` ```gdscript func _physics_process(delta: float) -> void: # [...] - match direction_discrete: - Vector2.RIGHT, Vector2.LEFT: - _skin.texture = RUNNER_RIGHT - Vector2.UP: - _skin.texture = RUNNER_UP - Vector2.DOWN: - _skin.texture = RUNNER_DOWN - UP_RIGHT, UP_LEFT: - _skin.texture = RUNNER_UP_RIGHT - DOWN_RIGHT, DOWN_LEFT: - _skin.texture = RUNNER_DOWN_RIGHT + if directions.has(direction_discrete): + _skin.texture = directions[direction_discrete] if direction_discrete.length() > 0: _skin.flip_h = sign(direction.x) < 0.0 ``` 1 1 Sep. 15, 2024
  • Question, related to direction_discrete.lenght()oliver_gzzHey there, got a little lost, of what **direction_discrete.lenght()**, when it comes to simplify the code and flip textures horizontally. Why shouldn't just be `if direction_discrete > 0:` And why, is `if direction_discrete GREATER THAN 0` shouldn't it be, less than 0 because we're moving the character to the left? thanks in advance! 4 0 Oct. 28, 2024
  • Question relating `sign()` functionAbdul Hannan AhmedHi! I just wanted to ask that in the following code: ```gdscript if direction_discrete.length() > 0: _skin.flip_h = sign(direction.x) < 0.0 ``` Why did we do `sign(direction.x)`. We already have a `direction_discrete: Vector2` which returns the `direction.sign()`. We could do: ```gdscript if direction_discrete.length() > 0: _skin.flip_h = direction_discrete.x < 0.0 ``` Was there any specific reason to use `sign(direction.x)`? 1 0 Sep. 15, 2024
Site is in BETA!found a bug?