django
September 15, 2024, 5:08pm
1
Hi i am new to Godot and i was trying to use a variable but it didn’t work when i added the if. Here is the code:
var direction = Input.get_vector(“left”, “right”, “up”, “down”)
if direction.x == 0 and direction.y == 0:
can anyone help me figure out what is wrong?
django:
but it didn’t work
What didn’t work? What did you expect to happen vs what really happened?
Make sure to make your code with proper formatting, and a little more code too please.
Posting here so to be linked for later use instead of re-typing this every time
Make sure you paste scripts instead of screenshots. To properly format pasted code use three ticks ``` at the start and end of your paste like so:
```
# type or paste code here
func _ready() -> void:
print("My ready function!")
```
Results in:
# type or paste code here
func _ready() -> void:
print("My ready function!")
Press the </> button or ctrl+e in the forum to create these ticks.
[2024-09-02…
django
September 15, 2024, 6:03pm
3
can some one please just tell me what to do to fix it
No, you need to give more information. It’s impossible for us to know what is wrong so it’s impossible to fix it succinctly.
1 Like
tayacan
September 15, 2024, 6:30pm
5
If that is literally all your code, then:
It needs to be inside a function (probably the _process function)
Something needs to happen in the if statement
Something like:
func _process(delta):
var direction = Input.get_vector(“left”, “right”, “up”, “down”)
if direction.x == 0 and direction.y == 0:
print("Direction is (0, 0)")
But as @gertkeno said, it’s hard to help more without you giving more information.
3 Likes