Godot Version
Godot 4.4.1
Question
Hi. This is my first time on here so if I do anything incorrectly please don’t hesitate to let me know, thanks!
So I’m interested in making games, but I’m not familiar with coding. So I have been doing my best to study python on W3schools for the past 2 months, doing their exercises etc. to try and rewire my brain to think like a programmer.
At the same time I am trying to follow along with GDscript tutorials, right now trying to follow a video by “Unain” explaining how to make 2d movements a bit more modular. I really like this idea, because that’s like making a template that works for other things in the future. (This is the exact video I’m following: https://youtu.be/yzbxoZFsU2Y?si=6FkKKbRr1Dsg3cNe)
The difficult bit is that I am very stubborn and will only be able to memorize/get things done if I understand the core fundamentals of how something work. So I find a lot of the youtube tutorials really hard to follow because most of them have to assume you know coding.
And that’s what brought me here: In Unain’s video, when it gets to the movement component, this is what he types (Unain’s example):
class_name MovementComponent
extend node
@export_subgroup("settings")
@export var speed: float = 100
func handle_horizontal_movement(body: CharacterBody2d, direction: float) -> void:
body.velocity.x = direction * speed
Unain goes on to explaining that direction is will change depending on which way the player is going; if it’s 1.0, then it’s going right, if it’s -1.0 then it’s going left, and if it’s 0 then the character isn’t moving.
I am also aware that people usually do (general example):
func _physics_process(delta):
var direction = Input.get_vector("go_left", "go_right", "go_up", "go_down")
velocity = direction * speed
move_and_slide()
Below are my questions:
- in Unain’s example, the direction is passed as an argument in the func and given the float type. But it was never explained why the direction can change from 0 to 1.0 or -1.0 when movement keys are pressed. In the general example, direction is a custom variable with the value:
Input.get_vector("go_left", "go_right"...etc)
so in my mind it makes a bit more sense how then direction * speed would be able to change.
- I have seen a lot about variable frame rates and how you MUST times things by delta, to keep things consistent across different PCs. But in Unain’s example, delta was not used. I was wondering why that is? (Now that i check, the general example doesn’t times direction and speed by delta either, but has delta as an argument within the _physics_process.
an extra question would be: sometimes i see delta as
delta
but some times i see it as:
_delta
I was just wondering why that is. I remember reading something about the underscore marking it as a built in godot name? I think i read that in the learn gdscript from Zero app.
Anyways, thank you so much for your time everyone! Really hoping I can get your professional insights from here and start making some games!