How to fix “Invalid call. Nonexistent function ‘length’ in base ‘bool’.” from Godot 3.3 tutorial

Godot Version - 4.2.2

Hi, I’m trying to make grappling hook for a 2d game using DevWorm’s tutorial. The only solution I found to this problem is in this post, however when I change motion = move_and_slide() to just move_and_slide() it doesn’t work.

	player_movement()
	jump()
	_hook()
	if hooked:
		gravity
		swing(delta)
		motion *= 0.975 #speed of the swing
		move_and_slide()
#=======================================
#swing (math processing that works out the physics (main reason the movement was rewritten around the grappling hook))
func swing(delta):
	var radius = global_position - hook_pos
	if motion.length() < 0.01 or radius.length() > 10: return
	var angle = acos(radius.dot(motion) / (radius.length() * motion.length()))
	var rad_vel = cos(angle) * motion.length()
	motion += radius.normalized() * -rad_vel
	
	if global_position.direction_to(hook_pos) > current_rope_length:
		global_position = hook_pos + radius.normalized() * current_rope_length
		
	motion += (hook_pos - global_position).normalized() * 15000 *delta

The line “if motion.length() < 0.01 or radius.length() > 10: return” is labeled as the cause of the error.

Go ahead and static-type the motion and radius var:

var motion: Vector2

func swing(delta):
    var radius: Vector2 = global_position - hook_pos
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.