Error cannot conver argument 1 from float to vector 2

hi so i am getting an error cannot convert argument 1 from float to vector 2

func climb_state(input_x, input):
		
		if not is_on_ladder(): state = MOVE
		velocity = input * 50
		velocity = move_and_slide(velocity, Vector2.UP)

my code

Need more code. :wink:

It’s saying that the first argument velocity is a float instead of a vector2. Is input a float too?

extends KinematicBody2D
class_name Player

enum{ MOVE, CLIMB }


export(Resource) var moveData

var velocity = Vector2.ZERO
var state = MOVE



onready var AnimatedSprite = $AnimatedSprite
onready var ladderCheck = $LadderCheck

func _ready():
print("hello world")
AnimatedSprite.frames = load("res://scenes/Player/playergreenskin.tres")

#delta means that it runs every frame of a second (right now its set to 60) so it will run every 1 frame of a second
func _physics_process(delta):    	
var input = Vector2.ZERO
var input_x = Vector2.ZERO
input_x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input.y = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")

match state:
	MOVE: move_state(input, input_x)
	CLIMB: climb_state(input, input_x)


func move_state(input, input_x):
	if is_on_ladder():
		state = CLIMB
	apply_gravity()
	if input_x == 0:
		apply_friction()
		# $ sign is shortcut for get_node("...")
		AnimatedSprite.animation = "Idle"
		AnimatedSprite.animation = "Idle"
	else:
		apply_acceleration(input_x)
		AnimatedSprite.animation = "Run"
		
		
		if input_x > 0:
			AnimatedSprite.flip_h = true
		elif input_x < 0:
			$AnimatedSprite.flip_h = false
	
	
	
	if is_on_floor():
		if Input.is_action_pressed("ui_up"):
			velocity.y = moveData.JUMP_FORCE 
		else:
			if Input.is_action_just_released("ui_up") and velocity.y < moveData.JUMP_RELEASE_FORCE:
				velocity.y = moveData.JUMP_RELEASE_FORCE
					


	var was_in_air =  not is_on_floor()
	velocity = move_and_slide(velocity, Vector2.UP)
	var _just_landed = is_on_floor() and was_in_air
	
	

func climb_state(input_x, input):
		
		if not is_on_ladder(): state = MOVE
		velocity = input * 50
		velocity = move_and_slide(velocity, Vector2.UP)
	  
func is_on_ladder():
	if not ladderCheck.is_colliding(): return false
	var collider = ladderCheck.get_collider()
	if not collider is Ladder: return false
	return true
	
func apply_gravity():
	velocity.y += moveData.GRAVITY
	velocity.y = min(velocity.y, 300)
	if velocity.y > 0:
				velocity.y += moveData.ADDITIONAL_GRAVITY

func apply_friction():
	velocity.x = move_toward(velocity.x, 0, moveData.FRICTION)

func apply_acceleration(amount):
	velocity.x = move_toward(velocity.x, moveData.MAX_SPEED * amount, moveData.ACCELERATION)
	

func _process(delta):
	if $AudioStreamPlayer2D.playing == false:
		$AudioStreamPlayer2D.play()

all of the code

Thanks, seeing everything is helpful.

Some things I noticed:

Why do you have an input var and an input_x var?
If you don’t define a type for your variables that can become anything.

# input_x will become a float.
input_x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")

# Later in func climb you want to set the velocity, which is a vector2 to a float (your input_x).
# That's where your error message came from.
# Use := to make input become the type of var you assign to it. So you get error messages in editor when trying to set it to something different than a Vector2.
var input := Vector2.ZERO

# As input is a vector 2 there is no need for a seperate input_x. Use input.x
input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input.y = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")

Right now I don’t see why you need a seperate input_x.
Vector2 have a x and a y direction. Maybe you didn’t know that.

Here you pass in input as first argument, and input_x as second:

match state:
	MOVE: move_state(input, input_x)
	CLIMB: climb_state(input, input_x)

Here you swapped the parameters names:

func climb_state(input_x, input):
		
		if not is_on_ladder(): state = MOVE
		velocity = input * 50 
		velocity = move_and_slide(velocity, Vector2.UP)

EDIT: Just saw you are using Godot 3.
Not sure if static typing works with := there. :confused: