Y component of Vector2 not returning

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kshitijsharmaa

I have been following GDquest’s “Your first game” tutorial, I made the function get_direction, however, it is not returning the Y component of Vector2. Here is the code:


var strength_track = 0.0

func _physics_process(delta: float) -> void:
 var move_dir = get_direction()
 print(move_dir.x)
 if move_dir.x == 0.0:
 	$AnimatedSprite.play("Idle")
 elif move_dir.x < 0.0:
 	$AnimatedSprite.flip_h = true
 	$AnimatedSprite.play("Walk")
 elif move_dir.x > 0.0:
 	$AnimatedSprite.flip_h = false
 	$AnimatedSprite.play("Walk")
 velocity =  speed * move_dir
 velocity = move_and_slide(velocity)

func get_direction() -> Vector2:
 return Vector2(
 	Input.get_action_strength("Right") - Input.get_action_strength("Left"),
 	-1.0 if Input.is_action_just_pressed("Jump") and is_on_floor()  else 1.0
 )```

[wrap=comment]
Actually your code should always return a value as conditional statement returns 1.0 as default on Y. 

How can you say it is not returning a value? 
As of now the default applies gravity and makes the player fall when it is not on floor.
Jump applies -1 giving a vertical impulse, only just after Jump button is pressed.

Just to verify you could mess around using is_action_pressed() to verify that the jump input is correct.
[wrap=footnote]gioele | 2020-08-28 22:07[/wrap]
[/wrap]