![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Emor |
Hi! I’m following HeartBeasts tutorial on smooth top-down movement, trying to get the same results. However, I’m using godot 4.0 and the tutorial is from 3.1 so I am getting an error: Invalid call. Nonexistent function ‘length’ in base ‘bool’.
I’m having trouble understanding what this errior means and why it’s there as I have copied his code from the video and I am very new to this. Help?
My code:
extends CharacterBody2D
@export var max_speed = 500
@export var ACCELERATION = 2000
var motion = Vector2.ZERO
#==========================================================================
func _physics_process(delta):
var axis = get_input_axis()
if axis == Vector2.ZERO:
apply_friction(ACCELERATION * delta)
else:
apply_movement(axis * ACCELERATION * delta)
motion = move_and_slide()
#==========================================================================
func get_input_axis():
var axis = Vector2.ZERO
axis.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
axis.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
return axis.normalized()
#==========================================================================
func apply_friction(amount):
if motion.length() > amount:
motion -= motion.normalized() * amount
else:
motion = Vector2.ZERO
#==========================================================================
func apply_movement(acceleration):
motion += acceleration
if motion.length() > max_speed:
motion = motion.normalized() * max_speed